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

App_timer and RTC Calendar example confliction

I am using  timer ( created with app_timer and started with period of 1 sec ) and ported RTC calendar example in it . But both features do  not work together ( since RTC is used in both the example ) . I want to have a real time calendar which should print my current time with date -month- year and with that, periodically ,I need some timers( app timers) for sensor data acquisition and other task . So how can we achieve this ? 

exampled used : ble_app_blinky  ( ported RTC calendar and app timer )

SDK version : 15.3.0

Hardware : Nordic NRF 52 DK ( PCA10040)

Parents Reply Children
  • So what exactly is not working?

    refer attachment .

  • main code 

    int main(void)
    {
    // Initialize.
    log_init();
    clock_init();
    timers_init();
    system_clock_init();
    #if 0
    i2c_init();
    gpio_init();
    button_init();
    power_management_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();
    services_init();
    advertising_init();
    conn_params_init();
    advertising_start();
    #endif

    // Start execution.
    NRF_LOG_INFO("NRF_LOG_INFO is used for uart\n\n.");
    printf("Printf is used for rtt logs\n");
    NRF_LOG_INFO("Blinky example started.");


    printf("ADV sytarts .........\n");
    =============================================================

    //============================================================= calender
    #if 1
    uint8_t uart_byte;
    uint32_t year, month, day, hour, minute, second;
    //app_timer_pause();
    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_LFCLKSTART = 1;
    while(NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);

    nrf_cal_init();
    nrf_cal_set_callback(calendar_updated, 1);

    // nrf_delay_ms(1000);
    while(1){


    print_current_time();
    //NRF_LOG_INFO("RTC Time +++++++++++++++++++++\r\n");
    NRF_LOG_FLUSH();

    //app_timer_resume();


    nrf_delay_ms(1000);
    }
    #endif
    //===================================================================== calender ends
    // Enter main loop.
    for (;;)
    {
    idle_state_handle();
    }
    }

  • system_clock_init();

    inside this i have 

    bool system_clock_init(void)
    {
    app_timer_create(&m_repeated_timer_id1,
    APP_TIMER_MODE_REPEATED,
    timer_led_event_handler);
    app_timer_start(m_repeated_timer_id1, APP_TIMER_TICKS(1000), NULL);

    return true;
    }

  • This doesn't tell me much unfortunately. Try adding DEBUG to your preprocessor definitions and check the log. If it still doesn't print anything where it points to a specific place in your project, try setting a breakpoint in the app_error_fault_handler() in app_error_weak.c. Try setting a breakpoint in the cases:

    case NRF_FAULT_ID_SDK_ASSERT:

    and 

    case NRF_FAULT_ID_SDK_ERROR:

    Are any of them hit?

  • I have a app timer defined  inside system_clock_init() as ,

    app_timer_create(&m_repeated_timer_id1,
    APP_TIMER_MODE_REPEATED,
    timer_led_event_handler);
    app_timer_start(m_repeated_timer_id1, APP_TIMER_TICKS(1000), NULL);

    And this I am calling here in main.c 

    int main(void)
    {
    // Initialize.
    log_init();
    clock_init();
    timers_init(); <<<<<<<<<<<<<<<<<<<<<<<<< app timer init 
    system_clock_init(); <<<<<<<<<<<<<<<<< app timer create and start

    now just after this , I have added RTC calendar example code as ,

    uint8_t uart_byte;
    uint32_t year, month, day, hour, minute, second;
    //app_timer_pause();
    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_LFCLKSTART = 1;
    while(NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);

    nrf_cal_init();
    nrf_cal_set_callback(calendar_updated, 4);

    while(1){

    print_current_time();
    nrf_delay_ms(1000);
    }

    now this must print the date and time on UART as ,

    <info> app: Uncalibrated time: 01/01/70 - 00:00:00

    <info> app: Calibrated time: 01/01/70 - 00:00:00

    but just after this , it gives ,

    <error> app: Fatal error

    and this fatal error is because , I have started one app timer , once the timer expires after 1 second , 

    its not able to start again , it goes to RTC1_IRQHandler()  from below app_error_check .

    uint32_t err_code = app_sched_event_put(&timer_event, sizeof(timer_event), timeout_handler_scheduled_exec);
    APP_ERROR_CHECK(err_code);

    Which means , app_sched_event_put function is returning error .

    And this function is defined in app_timer.c inside below function .

    static void timeout_handler_exec(timer_node_t * p_timer)

    hoping this will clarify your doubts .

Related