Hello,
I have a few queries regarding the SPI read function implementation. I am attempting to communicate with a slave device (MCP2518FD CAN extender) via SPI in polling mode at 16.5 MHz.
Issue:
When reading the OSC register from the slave, the expected data is 0x60040000. Upon probing with an oscilloscope, the data on the SPI bus is correct (0x60040000). However, during the software read operation, the data observed in the debugger appears as 0x00600400 instead of the expected 0x60040000. The first byte is always received as zero during the read operation.
Scope Data below is 0x60040000
CNarendra_0-1737560240815.png
Debugger window of received data(0x00600400)
CNarendra_1-1737560325963.png
Modified Code:
To address this, I modified the code to perform a dummy read for flushing the RX FIFO immediately after writing the dummy data into the PUSH.R register. This modification resolves the issue, and the read operation now works as intended. kindly check below one
CNarendra_2-1737560370608.png
Additional Observations:
Interestingly, other slaves like FRAM and FLASH work fine without requiring the dummy read to flush the RX FIFO placement. After applying the dummy flush placement modification, these other slaves continue to work correctly without any issues, while the MCP2518FD slave now works as expected.
Question:
Is performing a dummy read to flush the RX FIFO immediately after writing dummy data into the PUSH.R register the correct approach? Are there any alternative or recommended ways to handle this scenario?
Looking forward to your guidance.
Thanks & Regards
Narendra C
@PetrS ,#MPC5674F ,#MPC5xxx