This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Writing to Timer1 EVENTS_COMPARE register doesn't seem to work

The nRF52810 datasheet shows the EVENTS_COMPARE register as RW, so I'm assuming that I can write to it.

But when I write to it, nothing happens.

Example.

I set up the timer to generate an event at 10 seconds and use a While statement to wait.

while (NRF_TIMER1->EVENTS_COMPARE[TMRCC1] == false);

During this 10 seconds, I wait for an interrupt from an incoming ESB packet.

In the ESB handler, I write to the EVENTS_COMPARE register so that when the handler is done,

the program doesn't have to finish waiting for the remainder of the 10 seconds.

NRF_TIMER1->EVENTS_COMPARE[TMRCC1] = true;

However, this doesn't do anything as the program still waits until the 10 seconds is done.

Any tips would be greatly appreciated.

Parents
  • Hello,

    So you are not using the NRF_TIMER1 itself to trigger the capture compare?

    Are you sure that you get the event on the ESB?

    Wouldn't it be easier to use an app_timer to do this? I believe so, but you may have some reason to not use that.

    Have you set the INTENSET register? I don't know whether this solves anything, but according to the spec, you can't generate a Compare event by writing to the register manually. Reading from infocenter's section about TIMER:

    "A COMPARE event is generated when the Counter is incremented and then becomes equal to the value specified in one of the capture compare registers"

    I suggest that you use a volatile variable in the ESB handler, and check:

    esb_handler()
    {
        esb_triggered = true;
    }
    
    while ((NRF_TIMER1->EVENTS_COMPARE[TMRCC1] == false) || !esb_triggered));

    BR,

    Edvin

  • That being said, it is very little power efficient to wait in a while loop like this. It will prevent the CPU from going to sleep. I'd suggest that you rather use the interrupts to do things, instead of waiting for interrupts to occur.

Reply Children
No Data
Related