This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

sht21 with nrf51822 measuring temperature

Hi,

I am trying to measure the temperature using sht21 sensor with nrf51822. I am using TWI to do this. When I try to send a data to the sensor the application cannot do that. The code for initializing and measuring the temperature is as follows:

static void twi_master_init(void)
{
ret_code_t ret_code;
//Setup SDA and SCL pin, twi frequency and interrupt priority
const nrf_drv_twi_config_t config =
{
   .scl                = 18, 
   .sda                = 17, 
   .frequency          = NRF_TWI_FREQ_100K,
   .interrupt_priority = APP_IRQ_PRIORITY_HIGH
};

do
{
    // Unncommend line below to setup TWI without an event handler
    //ret_code = nrf_drv_twi_init(&twiMaster, &config, NULL); 
    // Setup TWI with an event handler  
    ret_code = nrf_drv_twi_init(&twiMaster, &config, NULL, NULL);    
    if(ret_code!= NRF_SUCCESS)
    {
        break;
    }
    nrf_drv_twi_enable(&twiMaster);
}while(0);
 }

static void measureTemperature( int* temperature )
 {
ret_code_t err_code;
uint8_t command_address[1] = {0xF3U};
uint8_t read[2] = {0x0000U};

err_code = nrf_drv_twi_tx( &twiMaster, DEVICE_ADDRESS, command_address, sizeof(command_address), false);
SEGGER_RTT_printf(0, "variable value: %d\n", err_code);
//APP_ERROR_CHECK(err_code);

nrf_delay_ms(200);
nrf_drv_twi_rx( &twiMaster, DEVICE_ADDRESS, read, sizeof(read));

*temperature = ROUNDED_DIV( ((21965 * (*read)) >> 13) - 46850, 1000 );

   }

If I uncomment the line "APP_ERROR_CHECK(err_code);" the application crashes. Otherwise the Segger RTT shows that err_code is equal to 3.

What does this mean? How can I solve this error? Any help is appreciated.

Thanks in advance.

Edit: I dig in the code a little bit and found that err_code = 3 means that it is NRF_ERROR_INTERNAL. I have no idea what it means though.

Edit2: I was trying to debug the code by using a twi_event_handler. I noticed that the sht21 is giving ADRESS_NACK error. So the address is not acknowledged by the sht21. I am pretty sure the adress part of the code is correct though?

Edit3: Ok the problem is solved. The datasheet provided for my custom board was mistakenly written the .sda and .scl pins. I verified the correct pins and now it is working.

Thanks

Parents
  • This error is generated in nrf_drv_twi.c->twim_xfer where the actual transfer of the data is placed into the hardware.

    The documentation for the API nrf_drv_twi_tx shows that

    @retval NRF_ERROR_INTERNAL If an error was detected by hardware.

    This means that the the function has finished what it supposed to do what there were errors detected in TWI->ERRSRC module. Most probably this is an overrun error which means that you are not reading the data fast enough. The previous data in in RXD register was overwritten.

Reply
  • This error is generated in nrf_drv_twi.c->twim_xfer where the actual transfer of the data is placed into the hardware.

    The documentation for the API nrf_drv_twi_tx shows that

    @retval NRF_ERROR_INTERNAL If an error was detected by hardware.

    This means that the the function has finished what it supposed to do what there were errors detected in TWI->ERRSRC module. Most probably this is an overrun error which means that you are not reading the data fast enough. The previous data in in RXD register was overwritten.

Children
No Data
Related