Skip to main content
ORaji.1
Associate
November 28, 2020
Solved

STM32F401RE: I2C code works only while single stepping in debug mode

  • November 28, 2020
  • 1 reply
  • 923 views

Good day, I'm trying to interface the STM32F401RE with a DS3231 RTC module. The idea is to read from the time-keeping registers of the RTC module. Based on the code, I decided to set the 'hour' register to 6 and when the register is read, 6 is expected to be read. This code only works while single stepping in debug mode and not at runtime. I don't know why this is happening but if there's something I'm missing or getting wrong, I'd be glad to know.

The source code is in the attached file below.

This topic has been closed for replies.
Best answer by KnarfB

Don't want to dig deep into your register level code, just one remark:

if ((I2C1->SR1 & I2C_SR1_TXE)){

This should be a while loop where the code waits spinning in that loop until transmission is completed.

1 reply

KnarfB
KnarfBBest answer
Super User
November 28, 2020

Don't want to dig deep into your register level code, just one remark:

if ((I2C1->SR1 & I2C_SR1_TXE)){

This should be a while loop where the code waits spinning in that loop until transmission is completed.