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

using Peripheral examples with soft device (ble)

I can run peripheral examples in SDK folder like GPIO, Timer, Scheduler ... but when I want to Add somethings like GPIO to peripheral_UART_ble or timer or scheduler It didn't work well and timer or GPIO doesn't work at all.

this my code:

const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(2);

and

    void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)
    {
        static uint32_t i;
       // uint32_t led_to_invert = (1 << leds_list[(i++) % LEDS_NUMBER]);
       
        switch(event_type)
        {
            case NRF_TIMER_EVENT_COMPARE1:
    		printf("a\n");
                break;
            
            default:
                //Do nothing.
                break;
        }
    }
    /**@brief Application main function.
     */
    int main(void)
    {
    uint32_t err_code;
    bool erase_bonds;
    uint8_t  start_string[] = START_STRING;
    
    // Initialize.
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
    uart_init();
    buttons_leds_init(&erase_bonds);
    ble_stack_init();
    gap_params_init();
    services_init();
    advertising_init();
    conn_params_init();
    
    printf("%s",start_string);

    err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
   // APP_ERROR_CHECK(err_code);
    
	printf("%d",err_code);
	
	
    uint32_t time_ms = 500; //Time(in miliseconds) between consecutive compare events.
    uint32_t time_ticks;
    err_code = NRF_SUCCESS;
    err_code = nrf_drv_timer_init(&TIMER_LED, NULL, timer_led_event_handler);
    printf("%d",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);
    // Enter main loop.


for (;;)
    {
        power_manage();
    }
     }

I only enabled Timer2 and I didn't enable Clock or anything else. But my program restart and printf("a\n") run very very fast.

I think

nrf_drv_timer_extended_compare(
     &TIMER_LED, NRF_TIMER_CC_CHANNEL1, time_ticks,  NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK, true);

didn't effect

Parents Reply Children
No Data
Related