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

hts 221 ERROR 4 [NRF_ERROR_NO_MEM]

Hi!

I am developing a network of temperature and humidity sensors, using nrf52832 and hts221 with the ide ses ... for this, I am using thingy 52 as a peripheral that sends the data to a central. When trying to read the hts221 sensor, I receive the ERROR 4 on the console. I checked the code again and again, but I can't find out what I'm doing wrong.
I'm using SDK16, thingy 52 1.0.1 and delete the thingy firmware using nrfjrog and then upload my own firmware.

//
// Set up the TWI instance for the HTS221 sensor 
//
/* TWI instance ID. */
#define TWI_INSTANCE_ID             0
#define MAX_PENDING_TRANSACTIONS    33

NRF_TWI_MNGR_DEF(m_nrf_twi_mngr, MAX_PENDING_TRANSACTIONS, TWI_INSTANCE_ID);
NRF_TWI_SENSOR_DEF(m_nrf_twi_sensor, &m_nrf_twi_mngr, HTS221_MIN_QUEUE_SIZE);
HTS221_INSTANCE_DEF(m_hts221,&m_nrf_twi_sensor,HTS221_BASE_ADDRESS);

// TWI (with transaction manager) initialization.
static void twi_config(void)
{
    uint32_t err_code;

    nrf_drv_twi_config_t const config = {
       .scl                = 8,
       .sda                = 7,
       .frequency          = NRF_DRV_TWI_FREQ_100K,
       .interrupt_priority = APP_IRQ_PRIORITY_LOWEST,
       .clear_bus_init     = false
    };

    NRF_LOG_INFO("TWI HTS221 sensor starting.");
    NRF_LOG_FLUSH();

    err_code = nrf_twi_mngr_init(&m_nrf_twi_mngr, &config);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_twi_sensor_init(&m_nrf_twi_sensor);
    APP_ERROR_CHECK(err_code);

    err_code = hts221_init(&m_hts221);
    APP_ERROR_CHECK(err_code);
		
    err_code = hts221_avg_cfg (&m_hts221, HTS221_TEMP_SAMPLES_8, HTS221_HUMIDITY_SAMPLES_16);
    APP_ERROR_CHECK(err_code);
		
}

void m_temp_callback (uint32_t twi_result_t, int16_t * p_rawtemp)
{
      
      NRF_LOG_INFO("RAW TEMP : %d", rawtemp);
      temperature = hts221_temp_process(&m_hts221,  rawtemp)/8;  
      
}

void m_hum_callback(uint32_t twi_result_h, int16_t * p_rawhum)
{
     int tempF;

     NRF_LOG_INFO("RAW HUMIDITY : %d\n", rawhum);
     humidity = hts221_hum_process(&m_hts221,  rawhum)/2;
     //
     // 2nd task competed
     // Temperature and Humidity both processed
     // Display results
     tempF = temperature*1.8+32;
     NRF_LOG_INFO("Temp: %d Degrees C,  %d Degrees F", temperature, tempF);
     NRF_LOG_INFO("Humidity: %d%%\n", humidity)
}

void read_th()
{
      uint32_t err;
      // Submit temperature read command to TWI manager
      // m_temp_callback called when data is returned
      err = hts221_temp_read(&m_hts221, &m_temp_callback , &rawtemp);
      APP_ERROR_CHECK(err);
      // Submit humidity read command to TWI manager
      // m_hum_callback called when data is returned
      err = hts221_hum_read(&m_hts221, &m_hum_callback , &rawhum);
      APP_ERROR_CHECK(err);
}



  • Hi,

    The screenshot does not show all of the error message, but the full message will tell you which file and which line number the error code was detected. Can you check and let me know which function it was? Things will probably be a lot clearer once we know which function returned NRF_ERROR_NO_MEM.

  • Hi, Einar Thorsrud.

    The error occurs on line 223, when calling the function; hts221_temp_read(&m_hts221, &m_temp_callback, &raw_temp). In addition, the response to reading how am i register is 00, I don't know if, perhaps, that is the root cause of the memory error.

    When defining the scl and sda pins in the twi.config() function, I did it as follows;

    scl=8

    sda=7

    Is this pin configuration correct for the Thingy 52 and hts221 sensor?

    Thanks for your time!

  • Hi,

    hts221_temp_read() returns the return value from nrf_twi_sensor_reg_read(), and in that returns NRF_ERROR_NO_MEM if there is no memory in sensor buffer (nrf_balloc_alloc() call failed). Have you tried to debug to see what is happening exactly? 

    ruizdiazji said:

    scl=8

    sda=7

    Is this pin configuration correct for the Thingy 52 and hts221 sensor?

    Yes, this is correct for the Thingy:52.

  • I'm not sure what is the right way to properly debug.

    I did a more elementary test of the i2c bus, running the twi_scanner example and, although, in this case I didn't get a memory error, I couldn't read the address of any i2c device of thingy 52. What I did was to adapt the scl and sda pins of the twi_scanner example only.

    Is it a good practice to do the scan of the i2c bus first? Or should I concentrate on finding the memory error of my program?

    Thanks a lot.

  • Hi,

    ruizdiazji said:
    I'm not sure what is the right way to properly debug.

    To debug, you should build the project without optimization (select "Debug" from the build configuration dropdown in SES), and sue a debugger connected to the thingy. an nRF52 DK or similar can be used as a debugger via the debug out port (I assume that is what you are already doing).

    ruizdiazji said:
    I did a more elementary test of the i2c bus, running the twi_scanner example and, although, in this case I didn't get a memory error, I couldn't read the address of any i2c device of thingy 52. What I did was to adapt the scl and sda pins of the twi_scanner example only.

    I don't understand why scanning first improved this.

    ruizdiazji said:
    Is it a good practice to do the scan of the i2c bus first?

    No, there is no reason to scan the I2C bus when you know which I2C address the slave device(s) have.

    ruizdiazji said:
    Or should I concentrate on finding the memory error of my program?

    I would say so.

Related