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

Why 500ms delay is required in twi_sensor example code

1) Why nrf_delay_ms(500) is required in twi_sensor example, in main.c, while(true) loop? 

2) Is the __WFE(); interrupted by NRF_DRV_TWI_XFER_RX inside twi_handler?  

3) From my understanding, the example code will Tx command to the TWI sensor, then TWI sensor will return data continuously (never stop), right? 

int main(void)
{
    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();

    NRF_LOG_INFO("\r\nTWI sensor example started.");
    NRF_LOG_FLUSH();
    twi_init();
    LM75B_set_mode();

    while (true)
    {
        nrf_delay_ms(500);

        do
        {
            /**
            Assembly Instruction
              \brief   Wait For Event
              \details Wait For Event is a hint instruction that permits the processor to enter
                       a low-power state until one of a number of events occurs.
             */
            __WFE();
        }while (m_xfer_done == false);

        read_sensor_data();
        NRF_LOG_FLUSH();
    }
}

Thank you!!

Parents
  • Hi,

    1. It is not needed, the delay is just used to read the temperature at 500ms intervals. You can also read the sensor using a timer or at another point in the application.
    2. Yes, that is correct. The handler will set the flag to indicate to the main loop that the previous transfer is completed, which allows you to start a new transfer.
    3. The sensor is configured into a mode where it will output the temperature on every read. There is no need to write the register address first. If you are using a different sensor, it may not have this configuration mode. Please check the datasheet of the device.

    Best regards,
    Jørgen

Reply
  • Hi,

    1. It is not needed, the delay is just used to read the temperature at 500ms intervals. You can also read the sensor using a timer or at another point in the application.
    2. Yes, that is correct. The handler will set the flag to indicate to the main loop that the previous transfer is completed, which allows you to start a new transfer.
    3. The sensor is configured into a mode where it will output the temperature on every read. There is no need to write the register address first. If you are using a different sensor, it may not have this configuration mode. Please check the datasheet of the device.

    Best regards,
    Jørgen

Children
No Data
Related