You are here

PSoC 4 SPI receive problem | Cypress Semiconductor

PSoC 4 SPI receive problem

Summary: 4 Replies, Latest post by info_1585471 on 05 Sep 2016 04:37 AM PDT
Verified Answers: 0
Last post
Log in to post new comments.
info_1585471's picture
User
3 posts

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

 

user_1377889's picture
User
10717 posts

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

 

info_1585471's picture
User
3 posts

It works, 

THANK YOU, Bob!

Best regards 

Alex

user_1377889's picture
User
10717 posts

You are always welcome!

 

Bob

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

info_1585471's picture
User
3 posts

Im near Hamburg.

Very nice to meet you :)

 

Log in to post new comments.