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

Why I use TIMER1 in demo "ble_uart" and encounter error "NRF_BREAKPOINT_COND"

Hi engineers,

This is my timer init code. I place it before functions timers_init() and ble_stack_init().

#include "tim.h"
#include "led.h"

const nrf_drv_timer_t TIMER_SAMPLE = NRF_DRV_TIMER_INSTANCE(0);

/**
 * @brief Handler for timer events.
 */
void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)
{
    switch (event_type)
    {
        case NRF_TIMER_EVENT_COMPARE0:
            led1_toggle();
            break;

        default:
            //Do nothing.
            break;
    }
}

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

    //Configure TIMER_SAMPLE 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;

    timer_cfg.frequency          = (nrf_timer_frequency_t)9;
    timer_cfg.mode               = (nrf_timer_mode_t)0;
    timer_cfg.bit_width          = (nrf_timer_bit_width_t)0;
    timer_cfg.interrupt_priority = 7;
    timer_cfg.p_context          = NULL;


    err_code = nrf_drv_timer_init(&TIMER_SAMPLE, &timer_cfg, timer_led_event_handler);
    APP_ERROR_CHECK(err_code);

    time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_SAMPLE, time_ms);

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

    nrf_drv_timer_enable(&TIMER_SAMPLE);
}

app_init() includes led and timer init function.

/**@brief Application main function.
 */
int main(void)
{
    bool erase_bonds;

    ringbuffer_init();
    app_init();//include led and timer init code
    // Initialize.
    //uart_init();
    //log_init();

    //buttons_leds_init(&erase_bonds);
    //power_management_init();
    timers_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();
    services_init();
    advertising_init();
    conn_params_init();

    // Start execution.
    //printf("\r\nUART started.\r\n");
    //NRF_LOG_INFO("Debug logging for UART over RTT started.");
    advertising_start();

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

Cheers,

Sean

Parents
  • Hello,

    TIMER0 is reserved to the Softdevice, so please try one of the other TIMER instances. E.g., const nrf_drv_timer_t TIMER_SAMPLE = NRF_DRV_TIMER_INSTANCE(1); //TIMER1

    Best regards,

    Vidar

    Softdevice - System on Chip resource requirements

  • Hi Vidar,

    Thanks for your reply! It works, and I change the default configuration shown as below.

    I think the previous default frequency is too high(16MHz), so I cannot see the led blinks.

    #include "tim.h"
    #include "led.h"
    
    
    const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(1);
    
    /**
     * @brief Handler for timer events.
     */
    void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)
    {
        switch (event_type)
        {
            case NRF_TIMER_EVENT_COMPARE1:
                led1_toggle();
                break;
    
            default:
                //Do nothing.
                break;
        }
    }
    
    void tim_init(void)
    {
        uint32_t time_ms = 500; //Time(in miliseconds) between consecutive compare events.
        uint32_t time_ticks;
        uint32_t err_code = NRF_SUCCESS;
    
        //Configure TIMER_LED 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;
        {
            .frequency          = (nrf_timer_frequency_t)4,     /* 1MHz */
            .mode               = (nrf_timer_mode_t)0,          /* Timer mode */
            .bit_width          = (nrf_timer_bit_width_t)3,     /* 32 bit */
            .interrupt_priority = 7,
            .p_context          = NULL,
        };
        err_code = nrf_drv_timer_init(&TIMER_LED, &timer_cfg, timer_led_event_handler);
        APP_ERROR_CHECK(err_code);
    
        time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_LED, time_ms);
    
        nrf_drv_timer_extended_compare(
             &TIMER_LED, NRF_TIMER_CC_CHANNEL1, time_ticks, NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK, true);
    
        nrf_drv_timer_enable(&TIMER_LED);
    }
    

    Cheers,

    Sean

Reply
  • Hi Vidar,

    Thanks for your reply! It works, and I change the default configuration shown as below.

    I think the previous default frequency is too high(16MHz), so I cannot see the led blinks.

    #include "tim.h"
    #include "led.h"
    
    
    const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(1);
    
    /**
     * @brief Handler for timer events.
     */
    void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)
    {
        switch (event_type)
        {
            case NRF_TIMER_EVENT_COMPARE1:
                led1_toggle();
                break;
    
            default:
                //Do nothing.
                break;
        }
    }
    
    void tim_init(void)
    {
        uint32_t time_ms = 500; //Time(in miliseconds) between consecutive compare events.
        uint32_t time_ticks;
        uint32_t err_code = NRF_SUCCESS;
    
        //Configure TIMER_LED 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;
        {
            .frequency          = (nrf_timer_frequency_t)4,     /* 1MHz */
            .mode               = (nrf_timer_mode_t)0,          /* Timer mode */
            .bit_width          = (nrf_timer_bit_width_t)3,     /* 32 bit */
            .interrupt_priority = 7,
            .p_context          = NULL,
        };
        err_code = nrf_drv_timer_init(&TIMER_LED, &timer_cfg, timer_led_event_handler);
        APP_ERROR_CHECK(err_code);
    
        time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_LED, time_ms);
    
        nrf_drv_timer_extended_compare(
             &TIMER_LED, NRF_TIMER_CC_CHANNEL1, time_ticks, NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK, true);
    
        nrf_drv_timer_enable(&TIMER_LED);
    }
    

    Cheers,

    Sean

Children
No Data
Related