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

Add Timer to ble_app_uart

Hello.

I am using nrf52832 and Segeer Embedded Studio.

I want to add a timer function to the ble_app_uart example so that the sensor value is read every 50 ms.

So I added the contents of the timer example to the ble_app_uart example.

ble_app_uart example  : nRF5_SDK_15.3.0_59ac345\examples\ble_central\ble_app_uart_c\pca10040\s132\ses

timer example : nRF5_SDK_15.3.0_59ac345\examples\peripheral\timer\pca10040\blank\ses

There is no error when building.

And when I click the go button after debugging, there is no error.

However, if I click the break button to stop the program and then click the go button again, the program stops at NRF_BREAKPOINT_COND.

I don't know how to combine the timer in the ble_app_uart  example.

I have seen comments that using Timer 0 may be a problem. So now I am using Timer1.

I would be grateful if you could help me with my problem.

The main.c code is attached.

int main(void)
{
    uint32_t time_ms = 50; //Time(in miliseconds) between consecutive compare events.
    uint32_t time_ticks;
    uint32_t err_code = NRF_SUCCESS;

    // Initialize. 
    log_init(); 
    timer_init(); 
    uart_init(); 
    buttons_leds_init(); 
    db_discovery_init(); 
    power_management_init(); 
    ble_stack_init(); 
    gatt_init(); 
    nus_c_init(); 
    scan_init(); 
    //GYR_Init();

    //Configure TIMER for generating simple light effect - leds on board will invert his state one after the other.
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    err_code = nrf_drv_timer_init(&TIMER, &timer_cfg, timer_led_event_handler);
    APP_ERROR_CHECK(err_code);

    time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER, time_ms);

    nrf_drv_timer_extended_compare(
         &TIMER, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);

    nrf_drv_timer_enable(&TIMER);

    // Start execution.
    printf("BLE UART central example started.\r\n");
    NRF_LOG_INFO("BLE UART central example started.");
    scan_start();

    // Enter main loop.
    for (;;) 
    {
        idle_state_handle();
    }
}

Parents
  • Hi,

    This is due to the Softdevie asserting due to the starting and stopping the application in debugger. See this and this thread for more info on how to debug Softdevice applications.

    best regards

    Jared 

  • Thank you for answer.

    However, because I was new to nrf52832, I didn't understand it even after looking at the explanation.

    I have seen that the PRIMASK register should be set to 1.

    But I am not even sure where and how to set the PRIMASK register.

    You may be frustrated with me, but could you please teach me a little easier explanation or method?

  • Hi,

     

    There is no error when building.

    And when I click the go button after debugging, there is no error.

    However, if I click the break button to stop the program and then click the go button again, the program stops at NRF_BREAKPOINT_COND.

    You describe that the application works when you start it and only asserts if you try to stop and re-start it again. This is an expected result when you debug a Softdevice application. The reason that it asserts is that the softdevic will also be halted when you hit a breakpoint/pause the application in the debugger. This will cause the Softdevice to assert when you resume as it could no longer meet the timing requirements of BLE when it was halted. 

    You therefore have to restart the application after each time you pause/hit a breakpoint during debugging. 

    regards

    Jared 

  • If I use the BLE soft device, debugging by resetting the device every time I hit a breakpoint would make debugging very difficult. 

    Is there a different way of debugging when using Nordic devices to get around this limitation?

Reply Children
Related