FTDI Community

General Category => Discussion - Software => Topic started by: scorpioprise on November 27, 2019, 11:53:51 AM

Title: FT900 SPI read library error
Post by: scorpioprise on November 27, 2019, 11:53:51 AM
Hi everybody,
I have to admit my ignorance, but I asked more experts and I had the following solution.

I was using an external ADC as slave, that was sending me back wrong / corrupted packets.

The Library given (2.5.0) for spi has a bug in spi_readn(), that is the
Code: [Select]
uint8_t FifoScratch[64] variable is not initialized to zero.
Thus, when reading from spi, this leads to a spurious writes where there should be none and, as in my case, the slave recives data when not supposed, sometimes leading to erratic behaviour.
Simple solution, add to the original code, just after the declaration, a 
Code: [Select]

for (int j = 0; j < 64; j++) {
FifoScratch[j] = 0x00;
}
or whatever you like.

Hope this helps future users.