Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

PSoC™ 4

AlSa_1585471
Level 1
Welcome!
Level 1

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
Level 10
50 questions asked 10 questions asked 1000 solutions authored
Level 10

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
Level 1
Welcome!
Level 1

It works, 

   

THANK YOU, Bob!

   

Best regards 

   

Alex

0 Likes
Bob_Marlowe
Level 10
50 questions asked 10 questions asked 1000 solutions authored
Level 10

You are always welcome!

   

 

   

Bob

   

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

0 Likes
AlSa_1585471
Level 1
Welcome!
Level 1

Im near Hamburg.

   

Very nice to meet you 🙂

0 Likes