This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

TWI stops working - SDA bus always LOW

Hi!

I'm developing a project with nrf52832 and I'm getting some problems. The micro is only communicating with an accelerometer (MMA8453) and after some time the communication stops. Using a digital analyzer is possible observe that the SDA bus get stuck in LOW. I already tried to change the PULL UP resistors to smaller values (2.74k) and it keeps happening. I tried communicate with other slave and the same happens.

To fix that, I changed the configurations of nrf_drv_twi.c to work in push pull mode instead of pull up mode. I don't know if it is the correct way to do it.

I'm using the pins P02 (SDA) and P03(SCL) and changed the configuration to the following:

nrf_drv_twi_config_t twi_config;
twi_config.scl = CGPIO::I2C_SCL;
twi_config.sda = CGPIO::I2C_SDA;
twi_config.frequency = NRF_TWI_FREQ_250K;
twi_config.interrupt_priority = APP_IRQ_PRIORITY_HIGH;
    
nrf_drv_twi_init(&i2c_instance, &twi_config, NULL, NULL);
nrf_drv_twi_enable(&i2c_instance);

#define SCL_PIN_INIT_CONF     ( (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) \
                              | (GPIO_PIN_CNF_DRIVE_S0S1     << GPIO_PIN_CNF_DRIVE_Pos) \
                              | (GPIO_PIN_CNF_PULL_Pullup    << GPIO_PIN_CNF_PULL_Pos)  \
                              | (GPIO_PIN_CNF_INPUT_Connect  << GPIO_PIN_CNF_INPUT_Pos) \
                              | (GPIO_PIN_CNF_DIR_Input      << GPIO_PIN_CNF_DIR_Pos))
#define SDA_PIN_INIT_CONF        SCL_PIN_INIT_CONF
  • That post has nothing at all to do with TWI, that's only concerned with drive strength when the pins are used as normal GPIOs. It doesn't mention TWI at all. So if changing that made a difference it's a total fluke and your bug, whatever it is, still persists.

    The manual is very clear that the GPIO settings ONLY matter when the peripheral is disabled. When the TWI is active, it takes full control of the pins and detaches them entirely from the GPIO system. Also the manual stipulates S0D1 must be used as the drive strength on the pins (for when the TWI is disabled and they are acting as regular GPIOs).

    So you may have masked your problem, but that is not the solution, and you've a fairly good chance it's coming back at some point.

  • I understand and I agree with you but, in practice something is happening. I left some demo working all night and in the morning it was working. If I change that, it crash after a few minutes. When I change the frequency of TWI to 100K it works a little longer. I know that's not the solution, thats why I'm asking for some help.

  • Hi, No I haven't. I'm using SDK 13 but it stills happening. I'm traying to find a solution but for now I didn't find it. Regards

  • @RK: Where in the documentation does it explicitly say that GPIO settings only matter when the peripheral is disabled? That may not be entirely correct.

    I talked to one of our TWI architects and he said that the GPIO settings actually do influence the pin even when the TWI is enabled. In other words, changing the drive strength from S0D1 to S0S1 will have an effect on the TWI bus. In light of this I suppose OP's issue might be related to the impedance of the TWI lines. The fact that lowering the frequency helps seems to support this.

    @Rafa:

    1. Are you able to look at the signals using an oscilloscope? Maybe the nRF52 struggles to drive the lines to correct voltage levels, and that might be easier to spot using an oscilloscope rather than a logic analyzer.
    2. Have you tried a different nRF52 device?
Related