- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If your Two more questions were not addressed in your newer threads, please create one.