NRF_ERROR_NO_MEM in nrf_twi_sensor_write

I'm getting an error NRF_ERROR_NO_MEM when trying to initialize the LPS22HB, and the RTT log shows:

<info> twi_sensor: Write register: 0x0B

<info> twi_sensor: Sensor addr: 0x5C Write length 2

<warning> twi_sensor: Memory not allocated. Sensor addr: 0x5C

<error> app: ERROR 4 [NRF_ERROR_NO_MEM] at :0

PC at: 0x00000000

<error> app: End of error report

The line being triggered is in nrf_twi_sensor.c, line 151, which is nrf_twi_sensor_write().

I've initialized the sensor like this:

NRF_TWI_MNGR_DEF(m_nrf_twi_mngr, MAX_PENDING_TRANSACTIONS, TWI_INSTANCE_ID);
NRF_TWI_SENSOR_DEF(m_twi_sensor, &m_nrf_twi_mngr, 128);
LPS22HB_INSTANCE_DEF(m_lps22b, &m_twi_sensor, TWI_ADDRESS);

int main(void)
{
    //...other code removed
    lps22hb_init(&m_lps22b);
    lps22hb_data_read(&m_lps22b,&barometer_callback,&baro_data,1);
    //...other code removed   
}

If I don't handle the error with APP_ERROR_CHECK() the rest of the program runs normally, except for not being able to read anything off the LPS22 sensor. Using nrf SDK version 17.0.2.

Parents Reply Children
  • Based on what I saw, I think I would try either of the approaches from the examples twi_sensor or twi_master_using_twi_mngr. One of them uses the twi sensor API, while the other uses the TWI mngr, but none of them use both. Just go with either one, and you should be fine.

    Best regards,

    Edvin

  • We've now re-implemented our own LPS22 driver using nrf_drv_twi_rx() and tx() functions without using the TWI Manager or the TWI sensor interface.

    Unfortunately TWI Sensor depended on TWI manager so we had to get rid of both, and we also don't have a working example of the Nordic LPS22 driver so we couldn't solve the error with nrf_balloc_alloc even with executing the twi_init() or twi_config() functions.

    So we're abandoning the Nordic LPS22 driver for now but we would still like to suggest creating an official example for it in the SDK in the future. Thanks for your help.

Related