cancel
Showing results for 
Search instead for 
Did you mean: 

Reading 0x00 in SPI_DR of SPI Communication

Sai Kalyan Marthi
Associate

Sir,

I am working on STM8S003F3P Controller which is interacting with LoRa SX1276 HPD Module. I have the experience of working on SPI and have enough knowledge to configure it.

I am able to write the data to SX1276 (I will tell you how).

But, while Reading the data from SX1276, SPI_DR register is always acting as follows.

If configured as input (Pulled up or High Impedance state), it is read as 0xFF

If configured as Output, it is read as 0x00 or 0xFF

Procedure to read the data is as follows

  1. Send the address first (MSB for Read or Write and 7 bit Register addresses of SX1276)
  2. After successful transmission, Send data to be written or dummy to read the data in address sent in step 1.

I have checked the waveforms for 3 to 5 registers using CRO and data is read accurately. but while keeping the controller in debug mode, unable to read the data in SPI_DR Register.

Tests Performed:

  1. Checked in debug
  2. Checking by sending the SPI_DR through UART.
  3. Checked data on CRO

First two tests are showing the same results but CRO waves are accurate.

Here are the configurations performed and data handled

Configurations:

while((!((SPI->SR & SPI_FLAG_TXE) == SPI_FLAG_TXE)) && (!((SPI->SR & SPI_FLAG_RXNE) == SPI_FLAG_RXNE))); //checking the transmission or reception

while((SPI->SR & SPI_FLAG_BSY) == SPI_FLAG_BSY);

SPI_DISABLE; //disable spi

SPI->CR1 = 0x3C; //clock divided by 256 (also tried the default divided by 2)

 SPI->CR2 = 0x01; //2 line uni directional, no crc, full duplex hardware management ssi master mode

SPI->ICR = 0x00; //no interrupts used (tried with rx interrupt but still the value is 00 or ff)

Data handling:

uint8_t SPI_REG_ACCESS(REG_READ_WRITE_Typedef READ_WRITE, LORA_REG_ADDRESS_Typedef REG_ADDRESS, uint8_t REG_DATA)

{

SPI_CS_LOW; //cs low

while(!((SPI->SR & SPI_FLAG_TXE) == SPI_FLAG_TXE)); //wait till transmit buffer empty

SPI->DR = (READ_WRITE | REG_ADDRESS); //Read or write is 0 or 1 respectively, reg_address is address of the register of sx1276

while((!((SPI->SR & SPI_FLAG_TXE) == SPI_FLAG_TXE))); //wait till buffer empty

SPI->DR = REG_DATA; //dummy value

while((!((SPI->SR & SPI_FLAG_RXNE) == SPI_FLAG_RXNE))); //wait till transmit complete

dummynew = SPI->DR; //read received data

while((SPI->SR & SPI_FLAG_BSY) == SPI_FLAG_BSY); //wait till busy

SPI_CS_HIGH; //cs high

return dummynew;

}

1 REPLY 1
Sai Kalyan Marthi
Associate

Issue solved.

Perhaps I have trusted the hardware too much. After booting the same firmware in other module. It found to be working fine.

Thanks for the views.