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();
    }
}

Related