I want to generate a pulse signal with PPI, timer2 and gpiote. But it doesn't work. Anything wrong with my code? void init_timer1() { NRF_TIMER1->PRESCALER = 1; NRF_TIMER1->TASKS_CLEAR = 1; NRF_TIMER1->BITMODE = TIMER_BITMODE_BITMODE_16Bit; NRF_TIMER1->CC[0] = 1000; NRF_TIMER1->CC[1] = 8000; //1k NRF_TIMER1->MODE = TIMER_MODE_MODE_Timer; NRF_TIMER1->SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Msk; NRF_TIMER1->SHORTS = TIMER_SHORTS_COMPARE1_CLEAR_Msk; NRF_TIMER1->EVENTS_COMPARE[0] = 0; NRF_TIMER1->EVENTS_COMPARE[1] = 0; NRF_TIMER1->INTENSET = TIMER_INTENSET_COMPARE1_Enabled << TIMER_INTENSET_COMPARE1_Pos; }
void sys_ini() { nrf_gpio_cfg_output(18); nrf_gpio_cfg_output(19); init_timer1(); }
/** @brief Function for initializing the GPIO Tasks and Events peripheral. */ static void gpiote_init(void) { nrf_gpiote_task_config(0, 19, NRF_GPIOTE_POLARITY_HITOLO, NRF_GPIOTE_INITIAL_VALUE_LOW); nrf_gpiote_task_config(1, 19, NRF_GPIOTE_POLARITY_LOTOHI, NRF_GPIOTE_INITIAL_VALUE_LOW); }
/** @brief Function for initializing Programmable Peripheral Interconnect (PPI) peripheral.
-
The PPI is needed to convert the timer event into a task. */ static void ppi_init(void) { // Configure PPI channel 0 to set current_pwm_out from high to low sd_ppi_channel_assign(0, &NRF_TIMER1->EVENTS_COMPARE[0], &NRF_GPIOTE->TASKS_OUT[0]); sd_ppi_channel_enable_set(1 << 0);
// Configure PPI channel 1 to set current_pwm_out from low to high sd_ppi_channel_assign(1, &NRF_TIMER1->EVENTS_COMPARE[1], &NRF_GPIOTE->TASKS_OUT[1]); sd_ppi_channel_enable_set(1 << 1); }
/**@brief Function for start hardware timers. */ void hard_timers_start(void) { sd_nvic_SetPriority(TIMER1_IRQn, 1); sd_nvic_EnableIRQ(TIMER1_IRQn); NRF_TIMER1->TASKS_START = 1; }
void TIMER1_IRQHandler() { // Clear interrupt NRF_TIMER1->EVENTS_COMPARE[0] = 0; NRF_TIMER1->EVENTS_COMPARE[1] = 0;
nrf_gpio_pin_toggle(18);
}
/**@brief Application main function. */ int main(void) { // Initialize leds_init(); timers_init(); buttons_init(); uart_init(); ble_stack_init(); gap_params_init(); services_init(); advertising_init(); conn_params_init(); sec_params_init();
sys_ini();
gpiote_init(); //Configure a GPIO to toggle on a GPIOTE task.
ppi_init(); //Use a PPI channel to connect the event to the task automatically.
//simple_uart_putstring(START_STRING);
hard_timers_start();
advertising_start();
// Enter main loop
for (;;)
{
power_manage();
}
}