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

problem with timer interrupts (NRF51822)

Hello,

i try to implement a simple timer interrupt on TIMER1 using one of the CC registers of the NRF51822. Here is my code:

void init_timers(void) {

// Start 32 MHz crystal oscillator
NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
NRF_CLOCK->TASKS_HFCLKSTART = 1;

// Wait for the external oscillator to start up
while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) {
	// Do nothing.
}

NRF_TIMER1->MODE = TIMER_MODE_MODE_Timer;
NRF_TIMER1->PRESCALER = TIMER_PRESCALER;

NVIC_EnableIRQ(TIMER1_IRQn);

NRF_TIMER1->CC[2] = 200;
NRF_TIMER1->INTENSET = TIMER_INTENSET_COMPARE2_Enabled
		<< TIMER_INTENSET_COMPARE2_Pos;

NRF_TIMER1->TASKS_START = 1;

    while(1);

}

void TIMER1_IRQHandler(void) { if (NRF_TIMER1->EVENTS_COMPARE[2] == 1) { NRF_TIMER1->EVENTS_COMPARE[2] = 0; //clear interrupt } }

When i try to debug my code and go into the while(1) loop the program counter (pc) get the value of 0xfffffffe. I suppose that the interrupt is generated but something goes wrong with the jump to the interrupt service routine void TIMER1_IRQHandler(void). Can explain to me how to implement a simple timer interrupt or provide a example. In the attachemnts is also my startUp file. I use GCC and eclipse.

best regards, Stefan

startup_nrf51.s

Parents
  • Your code looks correct, but could it be that the softdevice is enabled at the time you try this? If so, you'll get a HardFault when accessing the CLOCK peripheral, since this is blocked by the softdevice, and this may make Eclipse confused.

    If this is not the case, can you please edit your question, and supply your complete project, with makefiles and linker scripts, so I can give it a go?

    Edit: I'd also recommend you to take a look at this and this question for further details on potential problems with using Eclipse for debugging. It seems that Eclipse some times are a little problematic to get working reliably...

Reply
  • Your code looks correct, but could it be that the softdevice is enabled at the time you try this? If so, you'll get a HardFault when accessing the CLOCK peripheral, since this is blocked by the softdevice, and this may make Eclipse confused.

    If this is not the case, can you please edit your question, and supply your complete project, with makefiles and linker scripts, so I can give it a go?

    Edit: I'd also recommend you to take a look at this and this question for further details on potential problems with using Eclipse for debugging. It seems that Eclipse some times are a little problematic to get working reliably...

Children
No Data
Related