Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- volatile uint8_t data_rdy_flag = 0;
- int main(void)
- {
- uint32_t err_code;
- NRF_TIMER1->MODE = TIMER_MODE_MODE_Timer; // Set the timer in Timer Mode.
- NRF_TIMER1->PRESCALER = 7; // Prescaler 7 produces 125†000 Hz timer frequency => 1 tick = 8 us.
- NRF_TIMER1->BITMODE = TIMER_BITMODE_BITMODE_16Bit; // 16 bit mode.
- NRF_TIMER1->TASKS_CLEAR = 1; // clear the task first to be usable for later.
- NRF_TIMER1->CC[0] = 125;
- NRF_TIMER1->INTENSET = (TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos);
- /* Create an Event-Task shortcut to clear TIMER1 on COMPARE[0] event. */
- NRF_TIMER1->SHORTS = (TIMER_SHORTS_COMPARE0_CLEAR_Enabled << TIMER_SHORTS_COMPARE0_CLEAR_Pos);
- err_code = sd_nvic_SetPriority(TIMER1_IRQn,APP_IRQ_PRIORITY_LOW);
- APP_ERROR_CHECK(err_code);
- err_code = sd_nvic_ClearPendingIRQ(TIMER1_IRQn);
- APP_ERROR_CHECK(err_code);
- err_code = sd_nvic_EnableIRQ(TIMER1_IRQn);
- APP_ERROR_CHECK(err_code);
- NRF_TIMER1->TASKS_START = 1;
- while (1)
- {
- power_manage();
- if (data_rdy_flag != 0)
- {
- data_rdy_flag = 0;
- }
- }
- }
- void TIMER1_IRQHandler(void)
- {
- if (NRF_TIMER1->EVENTS_COMPARE[0] != 0)
- {
- NRF_TIMER1->EVENTS_COMPARE[0] = 0; //clear interrupt
- data_rdy_flag = 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment