Hello @stephanie_m , thank you for late reply.
So here is the thing. I believe that not me, or any other user should have to DEBUG how the chip works. That should be written in the documentation! Here, that is not the case!
While there is lot of information written about protocol signals, how they should look like in different protocol formats, the information how exactly the SPI module works is somewhat obscure. Namely, the module desciptions in the Documentation are on basic level and the examples provided in API Documenation (which your html link points to) are really basic. The infomation how something works exaclty, cannot be obtained from there. To add to that, how a module works with some specific settings would not be bad to have in the documentation.
So that is really something that NXP could work on. Improve the documenation.
Now lets get to the problem.
Chip_SSP_Int_FlushData() is not of any help. Since if one has TX half empty IRQ active, when the TX FIFO is being flushed, half way this IRQ will be triggered and a new batch is loaded. Also turning this IRQ off is not an option since one needs it for data to be loaded into FIFO. (There is no direct way to flush TX FIFO)
The key is in coordination between RX half full and TX half empty IRQs. If one wants to receive some amount of data and after some time when the clock comes, send a response, after recive the TX half full has to be turned off.
The following lines could be used in SPI IRQ handler to implement the stated.
if((sspSetupExample2.rx_cnt >= sspSetupExample2.length))
{
//disable TX half empty IRQ
NSS_SSP0->IMSC &= ~SSP_TXIM;
sspSetupExample2.rx_data = bufferSwitch;
sspSetupExample2.rx_cnt = 0;
}
if(sspSetupExample2.tx_cnt >= sspSetupExample2.length)
{
//disable TX half empty IRQ, enable RX half full and Timout IRQ
NSS_SSP0->IMSC |= SSP_RXIM;
NSS_SSP0->IMSC |= SSP_RTIM;
NSS_SSP0->IMSC &= ~SSP_TXIM;
}
Also one should not by any mean turn on TX half empty IRQ in IRQ Handler. sspSetupExample2.tx_cnt >= sspSetupExample2.length does not depict that the data have been clocked out of TX FIFO. After setting a buffer to send the data, g_sspSetup.rx_cnt >= g_sspSetup.length would depict when the data is sent.
One would have to test it and Debug it by itself to get how it exactly works.
I hope this could be helpful to someone.
Regards
Silabs