SPI. Relationship between Tx FIFO, Tx Buffer, Rx FIFO & Rx Buffer

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

cross mob
DaCh_4286001
Level 3
Level 3
First like received First like given

I am confused with the relationship between Tx FIFO, Tx Buffer, Rx FIFO & Rx Buffer. Please correct me if my understanding of this is incorrect.

In SPI, I am sending data from master to slave.

Data (suppose 10 characters) from master will be filled into Tx Buffer. Then it will move into Tx FIFO, which in hardware is 4 bytes. Then the data will be received by slave in Rx FIFO, move into Rx Buffer and being saved. After all data being received (Rx FIFO Empty), Rx Buffer size should be 10 because I transmitted 10 characters

Simon

0 Likes
1 Solution

I was not aware that master and slave were on the very same chip. Your project shows that.

When you remove the delays in your interrupt handler all runs well.

As a rule of thumb: Do not use delays or wait-loops within an interrupt handler. Keep handlers short. When applicable just set a (volatile) flag and act upon that in the main-loop.

Another solution would be to set the interrupt priority of your handler to the lowest, so it might get interrupted by all others. >Give it a try.

Happy coding

Bob

View solution in original post

0 Likes
9 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Generally your assuptions are correct.

Rx FIFO Empty shows that all data has been transferred to the transmitter, but the actual byte is not transferred yet. You could instead wait for RxBuffersize() becoming the expected number of transmitted bytes.

Bob

0 Likes

Thank you Bob,

But somehow RxBufferSize is not reading correctly.

I am sending alphabet "a~j" from SPIM which are 10 characters. so my Tx_data_count = 10;

Here is my code.

SPIM_pusharray(Tx_data, 10);

while((Tx_data_count != SPIS_GetRxBuffersize())

{

     a = SPIS_GetRxBuffersize();

}

It always shows that a = 4 which means the GetRxBuffersize() is only 4.

What might cause the problem?

0 Likes

I see two ambiguities in your code:

SPIM_pusharray(Tx_data, 10) <- You probably mean PutArray()

and

a = SPIS_GetRxBuffersize() <- Must be: a = SPIM_GetRxBuffersize()?

Can you please post your complete project so that we all can have a look at all of your settings. To do so, use

Creator->File->Create Workspace Bundle (minimal)

and attach the resulting file.

Bob

0 Likes
lock attach
Attachments are accessible only for community members.

Why it is SPIM_GetRxBufferSize() not SPIS_GetRxBufferSize()? In my mind data is transmitted from SPIM Tx Channel to SPIS Rx Channel so SPIS read data

Here is my code

0 Likes

I was not aware that master and slave were on the very same chip. Your project shows that.

When you remove the delays in your interrupt handler all runs well.

As a rule of thumb: Do not use delays or wait-loops within an interrupt handler. Keep handlers short. When applicable just set a (volatile) flag and act upon that in the main-loop.

Another solution would be to set the interrupt priority of your handler to the lowest, so it might get interrupted by all others. >Give it a try.

Happy coding

Bob

0 Likes

Thank you very much Bob,

It is working now. Thank you for the advice on interrupt coding.

I still have one more question: You say "I was not aware that master and slave were on the very same chip". So using SPIS GetRxBuffer size is correct. If master and slave are on different chips, but I still only want to only transfer data from master to slave, I think I will still only need to use SPIS GetRxBuffer. is this correct?

Simon

0 Likes

Having master and slave on different devices, master is a PSoC

When you trust in your master/slave connection you can be darn sure that for every byte the master sends a byte is sent back by the slave. Since some spi slaves are not user programmable (i.e.. interface chips) you cannot on PSoC master side check SPIS_xxxx API. But you can check how many bytes the master has got in its buffer by using SPIM_GetRxBufferSize() API

Bob

0 Likes

Thank you Bob,

I really appreciate your deep explanation.

Two more questions.

1. What problem might be caused if I use delay in ISR function?

2. If I increase the clock frequency up to 50 kHz, the code doesn't work again. But I think 50k is low frequency compare to 3Mhz which is used in sample code

Simon

0 Likes
Roy_Liu
Moderator
Moderator
Moderator
5 comments on KBA First comment on KBA 10 questions asked

If your Two more questions were not addressed in your newer threads, please create one.

Roy Liu
0 Likes