Timer1 on Nano 33 BLE

I am trying to blink and LED using timer1 on Nano BLE. this is no my end goal or could! just trying to understand how to set it up for how (right now I have no clue!).

Searching online I found this code and it Compiles and upload with no issue except that the LED does NOT BLINK! :sob:

Anyone having some experience with nRF timers could by any chance shed some light where the code might be wrong... ?

uint32_t counter = 0;

void init_sync_timer(void)
{
  NRF_TIMER1->TASKS_STOP = 1;
  NRF_TIMER1->MODE = TIMER_MODE_MODE_Timer;
  NRF_TIMER1->BITMODE =  TIMER_BITMODE_BITMODE_16Bit;
  NRF_TIMER1->PRESCALER = 4;
  NRF_TIMER1->CC[0] = 1000; //1000us(1ms)
  NRF_TIMER1->INTENSET = TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos;
  //NVIC_EnableIRQ(TIMER1_IRQn);
  NRF_TIMER1->TASKS_START = 1;
}

void TIMER1_IRQHandler(void)
{
  if (NRF_TIMER1->EVENTS_COMPARE[0])
  {
    counter++;
    if (counter == 500) {
      digitalWrite(7, !digitalRead(7));
      counter = 0;
    }
    NRF_TIMER1->EVENTS_COMPARE[0] = 0;
    NRF_TIMER1->CC[0] = 1000;
  }
}
void setup() {
  // put your setup code here, to run once:
  init_sync_timer();
  pinMode(7, OUTPUT);
  digitalWrite(7, HIGH);
}

void loop() {
  // put your main code here, to run repeatedly:

}

No experience with the Nano33 BLE. That construction might not be supported by the Nano33 BLE.

Try to use a flag that you toggle and write that to pin 7. Something like

volatile bool pin7State= true;
...
...
void TIMER1_IRQHandler(void)
{
  if (NRF_TIMER1->EVENTS_COMPARE[0])
  {
    counter++;
    if (counter == 500) {
      pin7State = !pin7State;
      digitalWrite(7, pin7State);
      counter = 0;
    }
    NRF_TIMER1->EVENTS_COMPARE[0] = 0;
    NRF_TIMER1->CC[0] = 1000;
  }
}

already tested that independently and it works for this board. but thanks anyway...

Managed to find a library for this! :sunglasses: