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

How to set timer delay for each of data for sending from nrf52840 to android apps ?

I have followed this tutorial from this link but cannot get it work.

  do
                    {
                       
                         int i;
                     
                       char buf[42];
                        for (i = 0; i < 3; i++) {
                      snprintf(buf,42, "A%dBBCCDDEEAABBCCDDEEAABBCCDDEEAABBCCDDXX", i);         
                      // puts string into buffer
                       printf("%s\n", buf); // outputs so you can see it

                       APP_TIMER_DEF(buf);
                          
   app_timer_create(&buf,APP_TIMER_MODE_REPEATED, uart_event_handle);
    app_timer_start(buf, APP_TIMER_TICKS(1000), NULL);

                         
                           uint16_t length2 = sizeof(buf);
      
                           err_code = ble_nus_data_send(&m_nus,buf, &length2, m_conn_handle);
                          


                       }
                      
                        if ((err_code != NRF_ERROR_INVALID_STATE) &&
                            (err_code != NRF_ERROR_RESOURCES) &&
                            (err_code != NRF_ERROR_NOT_FOUND))
                        {
                            APP_ERROR_CHECK(err_code);
                        }
                    } while (err_code == NRF_ERROR_RESOURCES);

I have 3 loop. For the first loop of sending data it will have a delay about 1s and until 2 finish. But there is no delay and it does not work.

Parents
  • Hello,

    The timer setup you use is something you haven't found in your link, right?

    I don't know what you expect, but I suspect that you expect the app_timer_create() and app_timer_start() to delay your application for 1 sec. Unfortunately it does not. Besides, you should check the return values from the functions that return values, such as app_timer_create() and app_timer_start. You will see that these will probably not return NRF_SUCCESS, at least not the second time.

    If you want to send a notification every 1000ms, you can trigger this from the interrupt handler in the timer, which looks like the uart_event_handle. You should create a separate event handler, not share it with the uart_event_handle. 

    The point of the APP_TIMER_MODE_REPEATED is that it will reset once you get the timeout event, so you should only start it once.

    Look at how the app_timer is used in the ble_app_hrs example. It uses this timer to send a new battery status notification on every timeout.

Reply
  • Hello,

    The timer setup you use is something you haven't found in your link, right?

    I don't know what you expect, but I suspect that you expect the app_timer_create() and app_timer_start() to delay your application for 1 sec. Unfortunately it does not. Besides, you should check the return values from the functions that return values, such as app_timer_create() and app_timer_start. You will see that these will probably not return NRF_SUCCESS, at least not the second time.

    If you want to send a notification every 1000ms, you can trigger this from the interrupt handler in the timer, which looks like the uart_event_handle. You should create a separate event handler, not share it with the uart_event_handle. 

    The point of the APP_TIMER_MODE_REPEATED is that it will reset once you get the timeout event, so you should only start it once.

    Look at how the app_timer is used in the ble_app_hrs example. It uses this timer to send a new battery status notification on every timeout.

Children
Related