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
  • So as an update, I increased LPS22HB_MIN_QUEUE_SIZE from 4 to 32 in lps22hb.h and the error has changed to 0x09 (NRF_ERROR_INVALID_LENGTH)...

  • Hello,

    Did you try to look inside nrf_twi_sensor_write() and debug to figue out why it returns 0x04/0x09? 

    When it returned 0x04, was it because nrf_twi_sensor_write_cmd_t * p_cmd was NULL? 

    When it returned 0x09, is it because length > NRF_TWI_SENSOR_SEND_BUF_SIZE? What is NRF_TWI_SENSOR_SEND_BUF_SIZE in your case?

    (All of these names are from inside nrf_twi_sensor_write())

    Best regards,

    Edvin

  • So I tested the project. I struggle to reproduce the issue on an nRF52832 DK without any additional HW connected. Are you able to reproduce it on an unmodified DK without any external SPI devices?

    Have you tried debugging to see the call trace when the issue occurs? Was it the nrf_twi_sensor_write() that caused the issue? What function called that function, and from what interrupt does this occur? Is it the timer interrupt? Does it trigger if the SPI device is not connected?

    Best regards,

    Edvin

  • Hi Edvin,

    We're using the u-blox EVK-BMD-330 which is using the nRF52810 and only has 24k of RAM. There's no SPI device - our custom board only has the LPS22HB and same LEDs and buttons as the DK.

    Does this mean that the block allocator doesn't have enough space? Can we reduce msg_buff_size for example in NRF_TWI_SENSOR_DEF?

  • So you are actually using an nRF52810. In that case, you should at least remove the two instances (!!) (CFLAGS and ASMFLAGS) in your makefile called DDEVELOP_IN_NRF52832)

    I don't know if that solves it, but did you try to increase the MAX_PENDING_TRANSACTIONS from 5 to at least 32 in your main.c file?

    Edvin said:

    So where does 5 come from? Is it your MAX_PENDING_TRANSACTIONS, or did you change:

    This was at least an issue, since the TWI is set up with this buffer size, and the init function required the buffer size to be larger than or equal to LPS22HB_MIN_QUEUE_SIZE, which you set to 32.

  • We've set the LPS22HB_MIN_QUEUE_SIZE back to 4. The main issue we're having is the nrf_balloc_alloc() call returning NULL, so we'll try removing the CFLAGS and ASMFLAGS for nrf52832.

    When you try to replicate the issue does the call to nrf_twi_sensor_write() finish without returning error 0x04?

  • presumably:

    Unless you sent me a project that doesn't use the twi. I assume it is called somehow from within lps22hb_data_read()?

    aonsquared said:
    We've set the LPS22HB_MIN_QUEUE_SIZE back to 4.

    If the issue originally was that the queue size was too small, I suggest that you try to set them both to 32, or even just 10, to see if the behavior changes.

    Best regards,

    Edvin

Reply
  • presumably:

    Unless you sent me a project that doesn't use the twi. I assume it is called somehow from within lps22hb_data_read()?

    aonsquared said:
    We've set the LPS22HB_MIN_QUEUE_SIZE back to 4.

    If the issue originally was that the queue size was too small, I suggest that you try to set them both to 32, or even just 10, to see if the behavior changes.

    Best regards,

    Edvin

Children
  • it's actually called from lps22hb_init() as well.

    The project I sent you needs a few changes to hit the error though - the line with lps22hb_init() needs to be changed to:

    ret_code_t err_code;
    err_code = lps22hb_init(&m_lps22b);
    APP_ERROR_CHECK(err_code);

    Otherwise the error is ignored and the rest of the code runs normally as I mentioned before.

  • I see.

    So, comparing your project with the twi_sensor example and the twi_master_using_twi_mngr example, yours is sort of a mix, with the exeption that you neither initiate the TWI nor the twi_mngr.

    I suggest you check out those samples from

    SDK\examples\peripheral\twi_master_using_nrf_twi_mngr

    SDK\examples\peripheral\twi_sensor

    And make sure you include one of the functions, twi_config() or twi_init() from either of those examples. 

    Depending on which approach you choose, you need to adjust the way you send twi messages, or how you initiate your sensor.

    Best regards,

    Edvin

  • Thanks! We'll try that.

    We just want to set a timer to poll the LPS22 sensor periodically and have no other devices, which option would be better for simplicity and code size?

  • 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