Hi,
I’m using Davinci DM6446evm Rev C. board and I’ve got an issue while trying to implement polling mode for SPI driver. More specifically, the read from SPI_BUF register does not seem to work as documented (or probably I’m missing a point somewhere).
Upon reading, I get the previous value stored in SPIBUF field of SPI Buffer register not the value that’s been read recently. The value however, gets copied to the SPIBUF field after a minor delay and subsequent reads to this register give me values which are out of sync by one read.
Here’s my code snippet that performs the reading job.
--------------------------------------------------------------
UINT32 temp32;
UINT32 buffer;
/* Wait for the Rx register to get non-empty. */
do
{
temp32 = READ_REG(SPI_BASE_ADDRESS + SPI_BUF);
}
while ( (temp32 & SPI_BUF_RXEMPTY) == 1);
/* Get the received data. Reading SPI Buffer is okay
for the second time since we will not get preempted
and subsequent reads to the register will not change
its values */
buffer = (READ_REG(SPI_BASE_ADDRESS +
SPI_BUF)) & SPI_BUF_RXDATA;
--------------------------------------------------------------
My observation is that introducing the slightest of delays (even a for loop to 10 will do the job) between the end of while statement and start of next will correct the values. Perhaps it gives time for the controller to actually place the value in SPIBUF.
I’ve verified from the manual that the SPIBUF field is populated prior to clearing out the RXEMPTY flag to indicate data presence.
Is this a known issue? If yes then what is the minimum delay that I need to introduce before reading SPIBUF field?
Any information that could help solving my problem will help.
Thanks!