I'm working with an SPI barometer trying to get the K22F reading SPI responses using an SPIMaster_LDD PE component. I've scoped the bus lines - everything looks correct. K22F sends a "read address" byte, barometer then clocks out the values for the byte, then CS is set high. I'm manually driving CS to ensure that it stays low between request/read transmissions.
I've had to add a work-around for the PE SPI driver bug where the function SM1_GetBlockReceivedStatus returns before the byte is actually recieved by adding a fixed delay afterwards:
char RecieveByteSPI1()
{
char b, dummy;
dummy = 0;
LDD_TError er;
er = SM1_ReceiveBlock(SPI1DeviceDataPtr, &b, 1);
er = SM1_SendBlock(SPI1DeviceDataPtr, &dummy, 1);
while (!SM1_GetBlockSentStatus(SPI1DeviceDataPtr)) {
SM1_Main(SPI1DeviceDataPtr);
}
// /* Wait until data block is transmitted/received */
while (!SM1_GetBlockReceivedStatus(SPI1DeviceDataPtr)) {
SM1_Main(SPI1DeviceDataPtr);
}
WAIT1_Waitms(2);
return b;
}
Using the delay, I can see that the SPI bus transaction happens correctly at the electrical level. However, the variable b is not populated when the code returns. The SPI1 register POPR/RXDATA shows that it holds the expected value just before this function returns.
SPI1 is configured to *not* use interrupts. Aside from that, it's basically at default settings. Any idea what could be going wrong here?
----------------------------------------------------------------------------------------------
Updates:
1) Manually reading from POPR after receiving seems to fix the issue. Not sure why this is necessary:
b = (uint16_t)SPI_PDD_ReadPopRxFIFOReg(SPI1_BASE_PTR); /* Read character from receiver */
2) I found other reports (Is anyone really using PE Generated SPI driver with MQXLite? How? ) of PE SPI issues where GetBlockReceivedStatus wasn't working and a different flag was used to check if reception was complete. However, it looks like the receive-commplete flag is never set, and my SendByteSPI1 function hangs on this line:
while (!(SPI_PDD_GetInterruptFlags(SPI1_BASE_PTR) & SPI_SR_EOQF_MASK));//wait for the end of transfer
I just noticed this issue related to using a GPIO for CS, although I'm using a different MCU:
SPI with no CS. Problem with PE
---------
Edit 2017-07-11
Here are a couple of discussions on what may be the same issue:
SPI Example
https://community.nxp.com/thread/342498