Girisha S

QN9020 SPI library issues faced

Discussion created by Girisha S on Apr 3, 2017

Hi,

 

I had been trying to use SPI 0 port of QN9020 to interface with AD7793 ADC. I tried to use the drivers and spi example provided in QBLUE package.

 

I had issues in reading and writing into the slave device. The signals probed on the CRO looked perfect but the SPI read API was not working properly as expected. There is no help available on the internet. So had to spend a lot of time to figure out the issue.

Solution:

Every write operation has to be followed by dummy read from the buffer. This will clear the RX fifo before reading the actual data.

 

For example, I have modified the tx function in driver_qn9020.h file as below ,

 

__STATIC_INLINE void spi_spi_SetTXD(QN_SPI_TypeDef *SPI, uint32_t data)
{
uint32_t dummyBuf;
__wr_reg((uint32_t)&SPI->TXD, data);
dummyBuf = __rd_reg((uint32_t)&SPI->RXD);

}

 

After I made this change, i was able to read properly all the data. Without this change if i want to read one byte from an address in the slave, then i have to call spi_read twice, and the result data would be JUNKBYTE+GOODBYTE

 

If i have to write a data first and then read ( WR_ADDR + DATA _W+ RD_DATA+DATA_R), then i had to read 4 times resulting JUNKBYTE+JUNKBYTE+JUNKBYTE+GOODBYTE.

 

So all the above JUNKBYTE are nothing but bytes pushed to RXFIFO during write operations, and they remain uncleared.

 

qblue should either fix this or give an API that will clear the RXFIFO.

 

Thanks,

Girisha S

Outcomes