Bharath G S
08/23/2023, 5:57 PMTim Edwards
08/23/2023, 7:06 PMhkspi
testbench is to exercise the housekeeping SPI, which is an SPI slave module, so CSB, SCK, and SDI are inputs to the SPI, and SDO is the output. The testbench defines sequences of commands it sends to the SPI to check the function, such as:
start_csb();
write_byte(8'h40); // Read stream command
write_byte(8'h03); // Address (register 3 = product ID)
read_byte(tbdata);
end_csb();
#10;
$display("Read data = 0x%02x (should be 0x11)", tbdata);
So the testbench applies signals to the chip asking the SPI slave to provide the data at SPI register address 3 (which is the product ID). The SPI responds by clocking out the contents of register 3 on SDO, which is why you should see SDO toggling.
Having an output enable on an SDO line is a typical feature of SPI slaves that allows multiple slaves to be connected together on the same SDO line. Only the slave with CSB asserted can control the common SDO line.Bharath G S
08/24/2023, 3:17 AMBharath G S
08/27/2023, 3:52 PMTim Edwards
08/27/2023, 3:58 PM