2025-03-09 3:34 PM
I've been designing STM32F devices for 15 years.
My first design using a "G" family - and it has NOT been easy.
SPI is a very simple device to use - my setup:
RCC->APBENR2 |= RCC_APBENR2_SPI1EN;
RCC->APBRSTR2 |= RCC_APBRSTR2_SPI1RST; // resset
NOP_Delay(0xf);
RCC->APBRSTR2 &= ~(RCC_APBRSTR2_SPI1RST); // resset
NOP_Delay(0xf);
SPI1->CR1 = (2 << SPI_CR1_BR_Pos) | SPI_CR1_MSTR | SPI_CR1_CPHA | SPI_CR1_SSM | SPI_CR1_SSI;
SPI1->CR1 |= SPI_CR1_SPE;
I'm using J-Link for debug and can confirm all the SPI1 registers look good.
SPI1->DR = 5; EXCEPT an instruction that writes to the DR register. The DR register stays at value 0.
I'm hoping it's not old age but I am lost as to the possible cause of this issue.
Any help/ideas?
Thanks.
2025-03-09 5:08 PM - edited 2025-03-09 5:45 PM
DR is a register to interfaces with the peripheral, not a memory address. Data you send to DR is written out (on MOSI for master). Data read from DR is what comes in to the device (on MISO for master).
Once you send data to DR, there is no way to read it back out. If you send two bytes to DR without any data being sent out yet (first one goes directly to shift register), the TXE flag will de-assert.
Also note that reading DR with a debugger will clear the RXNE flag which can cause issues if your program relies on behavior of that flag.