Page 1 of 3

i2c driver problem after resume from standby

Posted: Tue Feb 23, 2016 5:59 pm
by enrico.dallavia
Good evening,
I'm using a stm32 f429 chip, I have some peripherals which I control with i2c bus (I2CD1). When I first flash the device, all is working. But today I need to implement the standby, and now I am facing a problem. When the system restarts after an interrupt on pin0, the systems hangs (means no more thread working) when I make a call to i2c.

Code: Select all

i2cAcquireBus(&I2CD1);
status = i2cMasterTransmitTimeout(&I2CD1, isl29020_addr, txbuf, 2, rxbuf, 0, tmo);


the call to i2cAcquireBus(&I2CD1); works, means the system continues to working if for example I make a cycle like this:

Code: Select all

int i = 0;
do{
chThdSleepMilliseconds(250);
}while(i++ < 50);


but it hangs at i2cMasterTransmitTimeout.
From what I know, after a standby, everything is resetted (exept for the backup sram), so it is likely a start after reset.

does anyone know where could be the problem? I'm quite troubled by now!

Thanks a lot.

Re: i2c driver problem after resume from standby

Posted: Tue Feb 23, 2016 6:04 pm
by Giovanni
Try stopping drivers before entering the standby mode. After reset everything should be reinitialized.

Giovanni

Re: i2c driver problem after resume from standby

Posted: Tue Feb 23, 2016 6:07 pm
by enrico.dallavia
Thanks for the suggestion!
Is there any other driver that needs to be stopped before going to standby? like spi or exti ?

Re: i2c driver problem after resume from standby

Posted: Tue Feb 23, 2016 6:18 pm
by enrico.dallavia
Sorry, you wrote drivers, that means all drivers should be stopped before go to standby.

Re: i2c driver problem after resume from standby

Posted: Tue Feb 23, 2016 6:22 pm
by enrico.dallavia
I make a call to i2cStop(&I2CD1); just before go to standby.
unfortunately the problem still here, system hangs :(

Re: i2c driver problem after resume from standby

Posted: Tue Feb 23, 2016 7:25 pm
by Giovanni
Is it just I2C? do other peripherals work?

Giovanni

Re: i2c driver problem after resume from standby

Posted: Wed Feb 24, 2016 10:22 am
by enrico.dallavia
I've tried SPI,

Code: Select all

  unsigned char header_master[2] = {0x0a, 0x00};
        unsigned char header_slave[2]  = {0xaa, 0x00};

        chprintf((BaseSequentialStream *)&SERIAL_PORT, "SPI\r\n");
        chThdSleepMilliseconds(300);

        spiStart(&SPID3, &spiCfg);

        spiAcquireBus(&BLUE_NRG_SPI);

        spiSelect(&BLUE_NRG_SPI);

        spiExchange(&BLUE_NRG_SPI, 1, header_master, header_slave);

        spiUnselect(&BLUE_NRG_SPI);

        spiReleaseBus(&BLUE_NRG_SPI);


It works, or at least it does not hang.

After I wrote a i2c call

Code: Select all


..........
 spiReleaseBus(&BLUE_NRG_SPI);

 chprintf((BaseSequentialStream *)&SERIAL_PORT, "i2c\r\n");

 int ret = i2cMasterTransmit(&I2CD1, 0, &ch, 1, 0, 0);


it hangs (from serial I can only see "i2")

Re: i2c driver problem after resume from standby

Posted: Wed Feb 24, 2016 10:41 am
by Giovanni
Assuming that the code is correct, this makes me think to an HW origin for this issue because it seems to affect I2C only. You may try to reset I2C using RCC after exiting the standby mode.

Giovanni

Re: i2c driver problem after resume from standby

Posted: Wed Feb 24, 2016 10:46 am
by enrico.dallavia
Thanks, I wil try and let you know.

best regards

Re: i2c driver problem after resume from standby

Posted: Wed Feb 24, 2016 11:15 am
by enrico.dallavia
Nope,

Code: Select all

RCC->APB1RSTR |= 0x00200000; // Reset i2c peripheral
RCC->APB1RSTR &= 0xFFDFFFFF;

i2cStart(&I2CD1, &i2cfg1);

chprintf((BaseSequentialStream *)&SERIAL_PORT, "i2c\r\n");
int ret = i2cMasterTransmit(&I2CD1, 0, &ch, 1, 0, 0);


still hangs :(

and I give a i2cStop before go to standby

ps: the driver already calls a rccResetI2C1(); inside i2c_lld_start, so I guess what I've done is not necessary