Other Parts Discussed in Thread: OMAPL138,
Tool/software: TI-RTOS
Hi,
I am developing a driver for the SPI interface, I do not want to use interrupts so I am developing with polling.
I can transmmit correctly and my slave SPi is sending correctly the response, the problem is that I can not control when the response byte is received.
I show my source code and try to explain the problem:
/*Clear reception flag: write 1 in the SPI_SPIFLG in RXINTFLG*/ (First line)
ClearSPIFlagReceptionBuffer(uiSPIReg);
/*Write data in SPI_SPIDAT1*/
SPITransmitData1(uiSPIReg, pucOutBuffer, CS_NONE_UI); --> Correct send of the byte
// Wait to the byte is sent
uiStatusSPI = SPIFlagStatus(uiSPIReg);
while (!(uiStatusSPI & SPI_SPIFLG_TXINTFLG_UI)){
uiStatusSPI = SPIFlagStatus(uiSPIReg);
}
/*Wait for TXBUF Available*/
while (SPIReceiveBufferEmpty(uiSPIReg))
{
}
/*Now a new byte is received in SPI_SPIBUF. I read it*/
usReceivedData = SPIDataReceive(uiSPIReg);
/*I save the input byte*/
pucInBuffer[uiNumReceivedData] = (Char_uc)usReceivedData;
uiNumReceivedData++;
/*I send a new byte*/
SPITransmitData1(uiSPIReg, ucZero, CS_NONE_UI);
/*Check the byte has been transfered*/
uiStatusSPI = SPIFlagStatus(uiSPIReg);
while (!(uiStatusSPI & SPI_SPIFLG_TXINTFLG_UI)){
uiStatusSPI = SPIFlagStatus(uiSPIReg);
}
/*Wait for TXBUF Available*/
while (SPIReceiveBufferEmpty(uiSPIReg))
{
}
// FAIL: usReceivedData is sometimes the response of the second byte and others the response of the first byte transmitted.
usReceivedData = SPIDataReceive(uiSPIReg); (FAIL line)
Also I have checked that if I execute in debug mode and I stop in the last line (FAIL LINE) the response byte is always read correctly, so it can be a time error.
Also I have notice a weird behaviour with the CS and SPI_SPIDAT1. When I write SPIDAT1 with new data, data is sent and the SPI CLK is also sent (in case the CS is low), correct behaviour. However if I update the CS value in the SPIDAT1 to set to HIGH, the SPI CLK and MOSI are also sent when I do not want to sent a new data value, only I want to update the CS.
I have tried modifying only the byte where the CS is in SPIDAT1, but the SPI CS is not update although I can check in the debug register that the value is updated to high (I check in my oscilloscope that the SPI CS signal is still low).
HWREGB(uiBaseAdd + SPI_SPIDAT1_UI+2) = (Char_uc) uiCSNR ;
Thank you very much.
Best regards,
Lucía