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);
}
}
}