TWI causes NRF_ERROR_INTERNAL and fatal error

I have a hardware with NRF52832 module and successfully used the example twi-scanner to locate my I2C peripheral. I copied these parts over:

ret_code_t m41t62_init()
{
ret_code_t err_code;
const nrf_drv_twi_config_t twi_config = {
.scl = RTC_SCL, //pin 14
.sda = RTC_SDA, //pin 18
.frequency = NRF_TWI_FREQ_100K,
.interrupt_priority = APP_IRQ_PRIORITY_HIGH,
};
err_code = nrf_drv_twi_init(&m_twi, &twi_config, m41t62_twi_event_handler, NULL);
APP_ERROR_CHECK(err_code);

nrf_drv_twi_enable(&m_twi);

return err_code;
}

uint32_t m41t62_test()
{
    uint8_t data;
    ret_code_t err_code = nrf_drv_twi_rx(&m_twi, 0x68, &data, sizeof(data));
    APP_ERROR_CHECK(err_code);
    return data;
}

My own code produces this error on the line APP_ERROR_CHECK(err_code); in m41t62_test:

<info> TWI: Transfer type: XFER_RX.
<info> TWI: Transfer buffers length: primary: 1, secondary: 0.
<warning> TWI: Function: nrfx_twi_xfer, error code: NRF_ERROR_INTERNAL.
<error> app: ERROR 3 [NRF_ERROR_INTERNAL] at ./driver/m41t62lc6f.c:68
PC at: 0x0002CA85
<error> app: End of error report

What might be a difference that causes this?

Parents
No Data
Reply
  • Error 3 usually means something is pulling the SDA line low.  Verify you are using the correct pins. Are you missing some pull ups? If you have no external pull ups mounted, try

    twi_config.scl_pull = NRF_GPIO_PIN_PULLUP;
    twi_config.sda_pull = NRF_GPIO_PIN_PULLUP;

    If that does nothing, then try to determine if the peripheral might be pulling the sda line low. In order to recover from this condition, uninitialise the twi, configure the SCL pin as output, toggle it 16 times with some delay, and re-initialise the twi and try again.

Children