Announcements
Community Announcement : Welcome to the NEW Cypress Developer Community.
cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

AlSa_1585471
New Contributor

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

0 Likes
4 Replies
Bob_Marlowe
Expert II

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

0 Likes
AlSa_1585471
New Contributor

It works, 

   

THANK YOU, Bob!

   

Best regards 

   

Alex

0 Likes
Bob_Marlowe
Expert II

You are always welcome!

   

 

   

Bob

   

PS: Where are you located? I live near Bremen.

0 Likes
AlSa_1585471
New Contributor

Im near Hamburg.

   

Very nice to meet you 🙂

0 Likes