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.
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.
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?
I see two ambiguities in your code:
SPIM_pusharray(Tx_data, 10) <- You probably mean PutArray()
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.
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
SPI Practice.cywrk.Archive02.zip 606.3 K
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.
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?
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
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
If your Two more questions were not addressed in your newer threads, please create one.