Guest User

Untitled

a guest
Jul 1st, 2014
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.37 KB | None | 0 0
  1. volatile uint8_t data_rdy_flag = 0;
  2.  
  3. int main(void)
  4. {
  5.     uint32_t err_code;
  6.  
  7.     NRF_TIMER1->MODE = TIMER_MODE_MODE_Timer;   // Set the timer in Timer Mode.
  8.     NRF_TIMER1->PRESCALER = 7;  // Prescaler 7 produces 125†000 Hz timer frequency => 1 tick = 8 us.
  9.     NRF_TIMER1->BITMODE        = TIMER_BITMODE_BITMODE_16Bit;  // 16 bit mode.
  10.     NRF_TIMER1->TASKS_CLEAR    = 1;                            // clear the task first to be usable for later.
  11.  
  12.     NRF_TIMER1->CC[0] = 125;
  13.     NRF_TIMER1->INTENSET = (TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos);
  14.     /* Create an Event-Task shortcut to clear TIMER1 on COMPARE[0] event. */
  15.     NRF_TIMER1->SHORTS = (TIMER_SHORTS_COMPARE0_CLEAR_Enabled << TIMER_SHORTS_COMPARE0_CLEAR_Pos);
  16.  
  17.     err_code = sd_nvic_SetPriority(TIMER1_IRQn,APP_IRQ_PRIORITY_LOW);
  18.     APP_ERROR_CHECK(err_code);
  19.     err_code = sd_nvic_ClearPendingIRQ(TIMER1_IRQn);
  20.     APP_ERROR_CHECK(err_code);
  21.     err_code = sd_nvic_EnableIRQ(TIMER1_IRQn);
  22.     APP_ERROR_CHECK(err_code);
  23.  
  24.     NRF_TIMER1->TASKS_START = 1;
  25.  
  26.     while (1)
  27.     {
  28.         power_manage();
  29.         if (data_rdy_flag != 0)
  30.         {
  31.             data_rdy_flag = 0;
  32.         }
  33.     }
  34. }
  35. void TIMER1_IRQHandler(void)
  36. {
  37.     if (NRF_TIMER1->EVENTS_COMPARE[0] != 0)
  38.     {
  39.         NRF_TIMER1->EVENTS_COMPARE[0] = 0; //clear interrupt
  40.  
  41.         data_rdy_flag = 1;
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment