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

non blocking delay

Hi,

I work with a ship nrf52832.

I try to realise a communication beetween an UART sensor and the ship.

When i send my command (app_uart_put), i use nrf_delay_ms fonction to wait the answer and synchnise my communication. 

But during the delay my bytes are not sent.

Actually my soft is based on the ble_perepherical/ble_app_uart SDK example.

Thanks for you help

Regards 

Guillaume

Parents
  • Hi,

    As AmbystomaLabs said, using nrf_delay_ms() or nrf_delay_us() will block other functions from being executed, eg. UART TX/RX, another work around is to create an application timer, there is an example tutorial for this on the website. try to search it and it will popup.

    note that this tutorial is not up-to-date so you have to modify it. e.g. APP_TIMER_INIT() is mentioned in sdk13+ but the actual function for this is app_timer_init(); notice the difference.

    just to give you some hints:

    - APP_TIMER_DEF(timer_id); //create a timer id

    -void timer_event_handler(void *p_context){ // do your things here};

    -initialize the timer and it should be statically allocated e.g.:

    static void init_timer(void)

    {

        ret_code_t err_code = app_timer_init();
        APP_ERROR_CHECK(err_code);

    }

    - create the timers and and then start it check the options by creating and statically allocating it:

    static void start_timers(void)

    {

        ret_code_t err_code;
        err_code = app_timer_create(&timer_id, APP_TIMER_MODE_REPEATED, timer_event_handler); // can also use the single shot mode
        APP_ERROR_CHECK(err_code);

        err_code = app_timer_start(timer_id, APP_TIMER_TICKS(2000), NULL); //e.g. for 2000 ms
        APP_ERROR_CHECK(err_code);

    }

    Now in the main() do the following:

    1 - first thing first: call the init_timer();

    2- start the timers: call start_timers();

    this is how it worked for me, I hope i could have helped as I also struggled with the tutorial since its a bit old and am also in my first steps.

    regards,

    Moe

Reply
  • Hi,

    As AmbystomaLabs said, using nrf_delay_ms() or nrf_delay_us() will block other functions from being executed, eg. UART TX/RX, another work around is to create an application timer, there is an example tutorial for this on the website. try to search it and it will popup.

    note that this tutorial is not up-to-date so you have to modify it. e.g. APP_TIMER_INIT() is mentioned in sdk13+ but the actual function for this is app_timer_init(); notice the difference.

    just to give you some hints:

    - APP_TIMER_DEF(timer_id); //create a timer id

    -void timer_event_handler(void *p_context){ // do your things here};

    -initialize the timer and it should be statically allocated e.g.:

    static void init_timer(void)

    {

        ret_code_t err_code = app_timer_init();
        APP_ERROR_CHECK(err_code);

    }

    - create the timers and and then start it check the options by creating and statically allocating it:

    static void start_timers(void)

    {

        ret_code_t err_code;
        err_code = app_timer_create(&timer_id, APP_TIMER_MODE_REPEATED, timer_event_handler); // can also use the single shot mode
        APP_ERROR_CHECK(err_code);

        err_code = app_timer_start(timer_id, APP_TIMER_TICKS(2000), NULL); //e.g. for 2000 ms
        APP_ERROR_CHECK(err_code);

    }

    Now in the main() do the following:

    1 - first thing first: call the init_timer();

    2- start the timers: call start_timers();

    this is how it worked for me, I hope i could have helped as I also struggled with the tutorial since its a bit old and am also in my first steps.

    regards,

    Moe

Children
No Data
Related