I2C init issue

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

angainor
Posts: 11
Joined: Mon Dec 20, 2021 6:43 pm
Been thanked: 2 times

I2C init issue

Postby angainor » Thu May 25, 2023 9:37 am

Hi,

I came across a strange problem with I2C init (ChibiOS-ver21.11.3). Basically, I have to start the I2C device twice, with a stop in between, to make any contact with my magnetometer:

Code: Select all

    i2cStart(&I2CD1, &i2c1cfg);
    chThdSleepMilliseconds(100);
   
    // If I don't execute the below lines...
    i2cStop(&I2CD1);
    i2cStart(&I2CD1, &i2c1cfg);
    chThdSleepMilliseconds(100);
   
    // ... the following I2C transmit hangs forever
    i2cMasterTransmit(dev, HMC5883L_I2C_ADDR, &reg, 1, in, n);


It seems that if I do stop and re-start I2CD1, everything works fine.

Is there something I am doing wrong?

m

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: I2C init issue

Postby Giovanni » Thu May 25, 2023 10:51 am

Hi,

It could be an HW issue, I2C bus can get stuck if a transaction is interrupted, for example by a CPU reset from the debugger.

Giovanni


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 20 guests