I'm using a STM32F4 Discovery board which has a STM32F407VG with a LIS3DSH accelerometer which is connected by SPI. I'm trying to read a register from the accelerometer and I tried writing the address of the register to SPI->DR. But SPI->DR shows an incorrect value in the System Viewer window and in the Memory window. I have attached a picture with the corresponding portions highlighted in yellow.
Is this an issue with Keil or a Microcontroller side issue?
From the reference manual:
The data register is split into 2 buffers - one for writing (Transmit Buffer) and another one for reading (Receive buffer). A write to the data register will write into the Tx buffer and a read from the data register will return the value held in the Rx buffer.
So, you cannot expect to read what you have written into DR.
Thanks for your reply.
Is there any method from which the TX buffer and RX buffer can be inspected manually?
I don't think so. You always read the RX buffer.
And note that this is very common throughout all types of microcontrollers - and, in fact, digital electronics in general.
Although these "Special-Function Registers" (SFRs) are memory-mapped, they are not memory! they are connections to hardware.
Bottom line: never assume that any SFR will read-back what you just wrote to it.
View all questions in Keil forum