2020-10-01 06:57 PM
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
2020-10-01 07:36 PM
> 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);
2020-10-02 01:31 AM
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?
2020-10-02 08:00 AM
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.