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

nvic registered interrupt doesn't work

Hi all,

my Setup :

  • nrf51822 QFAC Build Code A1,Waveshare Core51822 Board
  • keil microvision
  • nrf device family Pack 8.6
  • without Softdevice erased with openocd nrf51 mass_erase I hope this is right?
  • stlink/v2 debugger
  • keil target option: IROM1 Start=0x0, size=0x40000, IRAM1 start = 0x20000000, size=0x8000
  • keil linker option: R/O base=0x00000000, R/W base = x20000000
  • keil debug->settings->Flash Downloads: Ram for algorithm start = 0x20000000, size=0x4000

I would program a minimal exaple, LED on Pin 10 should blink every 5 seconds. This code works only when I don't use NVIC_EnableIRQ(RTC1_IRQn); in the start_rtc() function.

In Debug Mode: When I activate NVIC_EnableIRQ(RTC1_IRQn) the NRF_RTC1->EVENTS_COMPARE[0] is correctly set after 5 seconds, but the code hangs at nrf_gpio_pin_toggle(STATUS_LED_PIN). In RTC1_IRQHandler() I have set a debug stop it never arrives this stop. The pending flag in the NVIC for RTC1 is always 1.

Without debug Mode: the program neither doesn't work, when I activate NVIC_EnableIRQ(RTC1_IRQn).

#include <stdbool.h>
#include "nrf.h"
#include "nrf_gpio.h"

#define STATUS_LED_PIN		10

void start_rtc(void){

	NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_RC << CLOCK_LFCLKSRC_SRC_Pos);
	NRF_CLOCK->TASKS_LFCLKSTART = 1;
	while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0) {}
	NRF_RTC1->PRESCALER = 4095; // 8Hz = 125ms ticks
    NRF_RTC1->CC[0] = 5*8;	// 5 seconds
    NRF_RTC1->EVTENSET = RTC_EVTENSET_COMPARE0_Msk;
    NRF_RTC1->INTENSET = RTC_INTENSET_COMPARE0_Msk;
   // NVIC_EnableIRQ(RTC1_IRQn);
	NRF_RTC1->TASKS_START = 1;
}

void gpio_config(void){
	nrf_gpio_cfg_output(STATUS_LED_PIN);
}

void RTC1_IRQHandler(void){
   int debugstop = 0;
}

/**
 * main function
 */
int main(void)
{
	gpio_config();
	start_rtc();

    nrf_gpio_pin_set(STATUS_LED_PIN);

	while(1){

		//__SEV();
		//__WFE();
		//__WFE();
		
		if(NRF_RTC1->EVENTS_COMPARE[0] != 0){
			
			NRF_RTC1->EVENTS_COMPARE[0] = 0;
			NRF_RTC1->TASKS_CLEAR = 1;
			NVIC_ClearPendingIRQ(RTC1_IRQn);
			nrf_gpio_pin_toggle(STATUS_LED_PIN);	
		}
		
	}
	
}
Parents
  • I tried NRF_RTC1->EVENTS_COMPARE[0] = 0; inside the RTC1_IRQHandler. It doesn't help. In Debug Mode I never reach the Breakpoint (it is not red, it is an exclamation mark ) inside the RTC1_IRQHandler. I use the original arm_startup_nrf51.s where the handler is declared. First time the event is set I come into the if condition from main() and NRF_RTC1->EVENTS_COMPARE[0] = 0; works but the code hangs at nrf_gpio_pin_toggle(STATUS_LED_PIN); The core Registers looks Ok see screenhot:

    image description

Reply
  • I tried NRF_RTC1->EVENTS_COMPARE[0] = 0; inside the RTC1_IRQHandler. It doesn't help. In Debug Mode I never reach the Breakpoint (it is not red, it is an exclamation mark ) inside the RTC1_IRQHandler. I use the original arm_startup_nrf51.s where the handler is declared. First time the event is set I come into the if condition from main() and NRF_RTC1->EVENTS_COMPARE[0] = 0; works but the code hangs at nrf_gpio_pin_toggle(STATUS_LED_PIN); The core Registers looks Ok see screenhot:

    image description

Children
No Data
Related