AnsweredAssumed Answered

uint8_t TI_TDC1000_SPIByteReadReg(uint8_t addr) { uint8_t read_byte,inst; uint8_t dummy = 0x00;        inst = TDC1000_READ_BIT

Question asked by nguyen_phu.thinh.001 on Feb 21, 2017
Latest reply on Feb 22, 2017 by KIC8462852 EPIC204278916

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 enable

while (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.

 

 

Outcomes