Skip to main content
HABIJ.1
Associate III
October 2, 2020
Question

Hi, I'm having trouble sending data through SPI on the STM32L476RG with CubeIDE.

  • October 2, 2020
  • 3 replies
  • 815 views

In my debugging, I noticed something wierd with this line of code from HAL_SPI_Transmit macro :

hspi->Instance->DR = *((uint16_t *)hspi->pTxBuffPtr);

pTxBuffPtr being the Transmit Buffer which, in my case, is txBuff[1] the first element of a one-element array containing the register (0x50) to read in my sensor (the BME280 pressure sensor).

Well, the above line of code seems not to do the job as DR instance of hspi is equal to 0 after the execution of the line.

for further details, the txBuff array is of uint8_t type

Could someone help with this?

Rest regards

This topic has been closed for replies.

3 replies

TDK
October 2, 2020

> DR instance of hspi is equal to 0 after the execution of the line.

DR is a register, it's not a memory cell. Values you write are shifted out, values you read are from data coming in.

In other words, you should not assume the following:

SPI1->DR = 67;
assert(SPI1->DR == 67);

"If you feel a post has answered your question, please click ""Accept as Solution""."
HABIJ.1
HABIJ.1Author
Associate III
October 2, 2020

Thanks for the reply

Well, in my other SPI codes the DR register get loaded by the data pointed by pTxBuffPTr and I see it after the execution of the line given above

I am debugging line by line, so I think I would see the loading of DR register after the execution of the line as the execution will be stopped until the next execution step?

TDK
October 2, 2020

That's not how SPIx->DR works. You never see the value you load in there, unless you happen to receive the same value at that time. Doesn't matter if you're going step by step or not.

"If you feel a post has answered your question, please click ""Accept as Solution""."