I'm using RFduino that utilizes nRF51822. I need to set a timer1 as timer0 is used by the BLE stack, so I used the following code:
#define TRIGGER_INTERVAL 1000 // ms
void timer_config(void)
{
NRF_TIMER1->TASKS_STOP = 1; // Stop timer
NRF_TIMER1->MODE = TIMER_MODE_MODE_Timer; // taken from Nordic dev zone
NRF_TIMER1->BITMODE = (TIMER_BITMODE_BITMODE_24Bit << TIMER_BITMODE_BITMODE_Pos);
NRF_TIMER1->PRESCALER = 4; // 1us resolution
NRF_TIMER1->TASKS_CLEAR = 1; // Clear timer
NRF_TIMER1->CC[0] = TRIGGER_INTERVAL * 1000;
NRF_TIMER1->INTENSET = TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos; // taken from Nordic dev zone
NRF_TIMER1->SHORTS = (TIMER_SHORTS_COMPARE0_CLEAR_Enabled << TIMER_SHORTS_COMPARE0_CLEAR_Pos);
attachInterrupt(TIMER1_IRQn, TIMER1_Interrupt); // also used in variant.cpp to configure the RTC1
NRF_TIMER1->TASKS_START = 1; // Start TIMER
}
void setup() {
Serial.begin(115200);
timer_config();
}
void loop() {
while(1);
}
void TIMER1_Interrupt(void)
{
if (NRF_TIMER1->EVENTS_COMPARE[0] != 0)
{
Serial.println("Timer interrupt called");
NRF_TIMER1->EVENTS_COMPARE[0] = 0;
}
}
Unfortunately it doesn't work. If a replace "TIMER1" with "TIMER0" it works fine. I'm a newbie regarding interrupts, any suggestions ? Thanks