cancel
Showing results for 
Search instead for 
Did you mean: 

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

HABIJ.1
Associate III

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

3 REPLIES 3
TDK
Guru

> 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
Associate III

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?

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".