//#define TRIGGER_INTERVAL 100 // ms
int LED = 8;
//int LED1 = 7;
int i = 0;
void timer_config(void)
{
NRF_TIMER0->TASKS_STOP = 1; // Stop timer
NRF_TIMER0->MODE = TIMER_MODE_MODE_Timer; // taken from Nordic dev zone
NRF_TIMER0->BITMODE = (TIMER_BITMODE_BITMODE_24Bit << TIMER_BITMODE_BITMODE_Pos);
NRF_TIMER0->PRESCALER = 8; // 1us resolution
NRF_TIMER0->TASKS_CLEAR = 1; // Clear timer
NRF_TIMER0->CC[0] = 62500;
NRF_TIMER0->INTENSET = TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos; // taken from Nordic dev zone
NRF_TIMER0->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
NVIC_EnableIRQ(TIMER0_IRQn);
NRF_TIMER0->TASKS_START = 1; // Start TIMER
// digitalWrite(LED, HIGH);
// delay(3000);
//
}
void setup() {
Serial.begin(115200);
pinMode(LED,OUTPUT);
digitalWrite(LED, LOW);
delay(3000);
timer_config();
}
void loop() {
// digitalWrite(LED, LOW);
// delay(1000);
// digitalWrite(LED, HIGH);
// delay(1000);
// //digitalWrite(LED, HIGH);
// //digitalWrite(LED, HIGH);
//while(1);
}
void TIMER0_IRQHandler()
{
// digitalWrite(LED, LOW);
// delay(1000);
// digitalWrite(LED, HIGH);
// delay(1000);
if (NRF_TIMER0->EVENTS_COMPARE[0] != 0)
{
//Serial.println("Timer interrupt called");
NRF_TIMER0->EVENTS_COMPARE[0] = 0;
int i = i+1;
if(i%2 == 0)
{
digitalWrite(LED, LOW);
delay(1000);
}
else
{
digitalWrite(LED, HIGH );
delay(1000);
}
}
}
Hey this is my code for blinking an led using timer interrupt on nrf 52832board, there are no errors in the code but the code is not working as desired. The function TIMER_IRQHandler is not called during an interrupt.
can someone please help me to tackle this problem?