2017-02-21 12:33 AM
Dear all,
here is my code to read spi data:
uint8_t TI_TDC1000_SPIByteReadReg(uint8_t addr)
{ uint8_t read_byte,inst; uint8_t dummy = 0x00; inst = TDC1000_READ_BIT & addr; // for read make sure bit6 is 0 //GPIO_ResetBits(TI_TDC1000_CSn_PORT ,TI_TDC1000_CSn_PIN); // CS enablewhile (SPI_GetFlagStatus(SPI1, SPI_FLAG_TXE)== RESET);
SPI_SendData(SPI1, inst);while (SPI_GetFlagStatus(SPI1, SPI_FLAG_TXE)== RESET);
SPI_SendData(SPI1, dummy); /* Wait to receive a byte */ while (SPI_GetFlagStatus(SPI1, SPI_FLAG_RXNE) == RESET); /* Return the byte read from the SPI bus */ read_byte = SPI_ReceiveData(SPI1);return read_byte;
}
I using oscilloscope and see that the data is read = 0x45, but in my code
read_byte alway = 0xFF, I think somewhere wrong when spi recieve data.
2017-02-21 02:51 AM
Change the wait events for waiting for RXNE.
When TXE is set, the SPI is just starting to spit the byte out (and a new one can be pre-loaded)
When RXNE is set the whole byte has been shipped and one has arrived for reading.
You can toggle a GPIO to view when each wait happens respective to the SPI Clocks to debug.
2017-02-21 08:00 PM
Hi,
I toogle GPIO and see SPI_FLAG_RXNE = SET after recieved all data, I think that is correct?
Could you suggest me what i must fix with this bug?
'
Change the wait events for waiting for RXNE.
' what should I change?Thanks
2017-02-22 01:26 AM
Try replacing all the TXE flag test by RXNE flag test and see what happens.
2017-02-22 01:27 AM
wait for RXNE = 1