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

NRF52832 Bluetooth UART and RTC2

Hello everyone,

I've been struggling to use the Bluetooth UART example and the RTC2 module but so far I haven't succeeded.

Either I have Bluetooth, or RTC2, but not both. Here is how I've modified the UART example code:

void RTC2_IRQHandler(void){
    if(NRF_RTC2->EVENTS_COMPARE[0]){
        NRF_RTC2->EVENTS_COMPARE[0] = 0;
        NRF_RTC2->TASKS_CLEAR = 1;
	nrf_gpio_pin_toggle(22);
    }
}

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

    // Initialize.
    uart_init();
    log_init();
    timers_init();
    buttons_leds_init(&erase_bonds);
    power_management_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();

    nrf_gpio_cfg_output(22);	
 
/*  This code alone works, but when added here
    it doesn't!

    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    NRF_CLOCK->LFCLKSRC = 0x00; 
    NRF_CLOCK->TASKS_LFCLKSTART = 1;
    while(NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);
    NRF_RTC2->PRESCALER = 0xFFF;
    NRF_RTC2->EVTENSET = RTC_EVTENSET_COMPARE0_Msk;
    NRF_RTC2->INTENSET = RTC_INTENSET_COMPARE0_Msk;
    NRF_RTC2->TASKS_CLEAR = 1;
    NRF_RTC2->TASKS_START = 1;
    NRF_RTC2->CC[0] = 8 * 1;
    NVIC_SetPriority(RTC2_IRQn, 3);
    NVIC_ClearPendingIRQ(RTC2_IRQn);
    NVIC_EnableIRQ(RTC2_IRQn);
*/



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

I'm using nRF5_SDK_17.0.0_9d13099

Thank you in advance.

L. B.

Parents
  • Hello again!

    I've just discovered, that if I comment out the RC oscillator initialization, the code works.

    void RTC2_IRQHandler(void){
        if(NRF_RTC2->EVENTS_COMPARE[0]){
            NRF_RTC2->EVENTS_COMPARE[0] = 0;
            NRF_RTC2->TASKS_CLEAR = 1;
    	nrf_gpio_pin_toggle(22);
        }
    }
    
    /**@brief Application main function.
     */
    int main(void)
    {
        bool erase_bonds;
    
        // Initialize.
        uart_init();
        log_init();
        timers_init();
        buttons_leds_init(&erase_bonds);
        power_management_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();
    
        nrf_gpio_cfg_output(22);	
     
    
    /*  Works without this one
        NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
        NRF_CLOCK->LFCLKSRC = 0x00; 
        NRF_CLOCK->TASKS_LFCLKSTART = 1;
        while(NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);*/
        
        NRF_RTC2->PRESCALER = 0xFFF;
        NRF_RTC2->EVTENSET = RTC_EVTENSET_COMPARE0_Msk;
        NRF_RTC2->INTENSET = RTC_INTENSET_COMPARE0_Msk;
        NRF_RTC2->TASKS_CLEAR = 1;
        NRF_RTC2->TASKS_START = 1;
        NRF_RTC2->CC[0] = 8 * 1;
        NVIC_SetPriority(RTC2_IRQn, 3);
        NVIC_ClearPendingIRQ(RTC2_IRQn);
        NVIC_EnableIRQ(RTC2_IRQn);
    
    
        // Enter main loop.
        for (;;)
        {
            idle_state_handle();
        }
    }

    However I cannot turn on and off the Bluetooth. Basically I want the RTC2 to work always, and just turn on and off the Bluetooth at specific periods.

    Regards,

    L. B.

Reply
  • Hello again!

    I've just discovered, that if I comment out the RC oscillator initialization, the code works.

    void RTC2_IRQHandler(void){
        if(NRF_RTC2->EVENTS_COMPARE[0]){
            NRF_RTC2->EVENTS_COMPARE[0] = 0;
            NRF_RTC2->TASKS_CLEAR = 1;
    	nrf_gpio_pin_toggle(22);
        }
    }
    
    /**@brief Application main function.
     */
    int main(void)
    {
        bool erase_bonds;
    
        // Initialize.
        uart_init();
        log_init();
        timers_init();
        buttons_leds_init(&erase_bonds);
        power_management_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();
    
        nrf_gpio_cfg_output(22);	
     
    
    /*  Works without this one
        NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
        NRF_CLOCK->LFCLKSRC = 0x00; 
        NRF_CLOCK->TASKS_LFCLKSTART = 1;
        while(NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);*/
        
        NRF_RTC2->PRESCALER = 0xFFF;
        NRF_RTC2->EVTENSET = RTC_EVTENSET_COMPARE0_Msk;
        NRF_RTC2->INTENSET = RTC_INTENSET_COMPARE0_Msk;
        NRF_RTC2->TASKS_CLEAR = 1;
        NRF_RTC2->TASKS_START = 1;
        NRF_RTC2->CC[0] = 8 * 1;
        NVIC_SetPriority(RTC2_IRQn, 3);
        NVIC_ClearPendingIRQ(RTC2_IRQn);
        NVIC_EnableIRQ(RTC2_IRQn);
    
    
        // Enter main loop.
        for (;;)
        {
            idle_state_handle();
        }
    }

    However I cannot turn on and off the Bluetooth. Basically I want the RTC2 to work always, and just turn on and off the Bluetooth at specific periods.

    Regards,

    L. B.

Children
No Data
Related