Skip to main content
Explorer
October 12, 2024
Solved

STM32G491 restarts when using I²C

  • October 12, 2024
  • 1 reply
  • 820 views

Hi, 

I am having a problem with a unexpected restart.

The first time I use the I²C bus by invoking HAL_I2C_Master_Transmit, the MCU restarts after reaching this line:

line 7276 of stm32g4xx_hal_i2c.c

/* update CR2 register */
MODIFY_REG(hi2c->Instance->CR2, \
((I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RELOAD | I2C_CR2_AUTOEND | \
(I2C_CR2_RD_WRN & (uint32_t)(Request >> (31U - I2C_CR2_RD_WRN_Pos))) | \
I2C_CR2_START | I2C_CR2_STOP)), tmp);

 

It just goes straight to the reset handler, no hard fault is triggered. I am using I2C1, and that shares the BOOT0 pin with I²C1-SCL, but that should be irrelevant, as we are already running in the user code. I'm really at loss what is going on here. I appreciate any suggestions.

    This topic has been closed for replies.
    Best answer by Pavel A.

    So can your I2C2 actually use some pin that is shared with NRST? Look at the pin mapping in your code or CubeMX. Are the I2C2 wires touching ground?

     

     

    1 reply

    Pavel A.Answer
    Super User
    October 12, 2024

    So can your I2C2 actually use some pin that is shared with NRST? Look at the pin mapping in your code or CubeMX. Are the I2C2 wires touching ground?

     

     

    MHens.2Author
    Explorer
    October 12, 2024

    It doesn't, but your comment had me looking at NRST with my scope. It triggered.

    I found a solder ball under the microscope that shorted NRST to the I²C bus.

    Thanks!