alternate for nrf_delay_ms

hello,

i am using nrf52832 with lis3dh accelarometer and max30205 temperature sensor in our customised board with sdk 15.2 in my driver for temperature sensor i am using delay function

i need any alternate for delay function which consumes less current 

while (m_xfer_done == false)
;
nrf_delay_ms(5);// in this line i have to wait for 5 ms 

thanks and regards

manikanadan v

Parents
  • You could use a single shot app timer to configure as delay with timer that can make your system go to sleep while sleeping instead of busy while looping.

    App timer documentation can be found here

  • hello,

    i am doing something like this but that does not seems to be working

    static void delay_timeout_handler(void *p_context) {

    //what should i put here

    }

    void MAX_temp_mode(void) {

    while (m_xfer_done == false)
    ;

    app_timer_stop(timer_for_delay);
    err_code = app_timer_start(timer_for_delay, APP_TIMER_TICKS(5), NULL);
    //what should i put here

    }

    thanks and regards 

    manikandan v

  • There are similar requests in the devzone like this one.. That should help you to atleast show the logic of how to use a one shot delay using app_timer

  • hello,  

    i already know how to use an app timer 

    static volatile bool m_le_delay_flag = false;

    err_code = app_timer_create(&m_delay, APP_TIMER_MODE_SINGLE_SHOT, timer_evt_Delay);
    APP_ERROR_CHECK(err_code);

    static void power_manage(void) {
    uint32_t err_code = sd_app_evt_wait();
    APP_ERROR_CHECK(err_code);
    }

    /** function for calling low power delay */
    uint8_t nrf_delay_ms_app(int ms_delay) {

    uint32_t err_code;
    err_code = app_timer_start(m_delay, APP_TIMER_TICKS(ms_delay), NULL);
    APP_ERROR_CHECK(err_code);
    m_delay_flag = true;
    while (m_delay_flag) {
    power_manage();
    }
    return 0;
    }

    static void timer_evt_Delay(void *p_context) {

    printf("delay\n");
    m_delay_flag = false;
    }

    but when i call  nrf_delay_ms_app(10); in my application my program get alted in  bove while loop do you happen to know the reason befind this (note :i am calling this function inside an another app timer handler ) kindly check and tell me how can i rectify this

    thanks and regards

    manikandan v

Reply
  • hello,  

    i already know how to use an app timer 

    static volatile bool m_le_delay_flag = false;

    err_code = app_timer_create(&m_delay, APP_TIMER_MODE_SINGLE_SHOT, timer_evt_Delay);
    APP_ERROR_CHECK(err_code);

    static void power_manage(void) {
    uint32_t err_code = sd_app_evt_wait();
    APP_ERROR_CHECK(err_code);
    }

    /** function for calling low power delay */
    uint8_t nrf_delay_ms_app(int ms_delay) {

    uint32_t err_code;
    err_code = app_timer_start(m_delay, APP_TIMER_TICKS(ms_delay), NULL);
    APP_ERROR_CHECK(err_code);
    m_delay_flag = true;
    while (m_delay_flag) {
    power_manage();
    }
    return 0;
    }

    static void timer_evt_Delay(void *p_context) {

    printf("delay\n");
    m_delay_flag = false;
    }

    but when i call  nrf_delay_ms_app(10); in my application my program get alted in  bove while loop do you happen to know the reason befind this (note :i am calling this function inside an another app timer handler ) kindly check and tell me how can i rectify this

    thanks and regards

    manikandan v

Children
Related