- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
i am trying to read an external Flash over SPI.
On oszilloscope looks data well, but my variable a and b is wrong.
Code:
SPIM_SpiUartWriteTxData(0x03); // Readcomand
dummy = SPIM_SpiUartReadRxData();
SPIM_SpiUartWriteTxData(A_high); // Adress
dummy = SPIM_SpiUartReadRxData();
SPIM_SpiUartWriteTxData(A_mid); // Adress
dummy = SPIM_SpiUartReadRxData();
SPIM_SpiUartWriteTxData(A_low); // Adress
dummy = SPIM_SpiUartReadRxData();
SPIM_SpiUartWriteTxData(0x00); // Dummy
a = SPIM_SpiUartReadRxData();
SPIM_SpiUartWriteTxData(0x00); // Dummy
b = SPIM_SpiUartReadRxData();
I use SS Pin automatic. And a read 16 bit value (2 times dummy 0x00 at mosi pin)
My problem is, a und b is wrong.
Somebody know, was can the problem be? Component "SPIM" has default settings. Master Mode, CPOL 0
Thanks
Best regards
Alex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Welcome in the forum, Alex.
You are reading data before they are in the receive buffer.
try something like this
PIM_SpiUartWriteTxData(0x03); // Readcomand
SPIM_SpiUartWriteTxData(A_high); // Adress
SPIM_SpiUartWriteTxData(A_mid); // Adress
SPIM_SpiUartWriteTxData(A_low); // Adress
SPIM_SpiUartWriteTxData(0x00); // Dummy
SPIM_SpiUartWriteTxData(0x00); // Dummy
while (SPIM_SpiUartGetRxBufferSize < 6) {} // Wait
for(ii=0; ii < 4; ii++) SPIM_SpiUartReadRxData(); // Read off unused bytes
a = SPIM_SpiUartReadRxData();
b = SPIM_SpiUartReadRxData();
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It works,
THANK YOU, Bob!
Best regards
Alex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are always welcome!
Bob
PS: Where are you located? I live near Bremen.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Im near Hamburg.
Very nice to meet you 🙂