I2C init issue

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

Moderator: RoccoMarco

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

I2C init issue

Post by angainor »

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: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: I2C init issue

Post by Giovanni »

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
Post Reply