So I wrote a program for the STM32F103C8T6
microcontroller in C, using the RTC (Real Time Clock) and a display module.
The RTC and the display both work fine, but when I try to update the display from inside the RTC interrupt handler, it doesn't work.
When I write something to the display from within the main()
, it works just fine.
The interrupt handler works as well, so I figured that the problem lied within the function that writes to the display.
This function uses small delays to bit-bang the communication with the display controller.
I previously used the SysTick
to generate the delays like this:
void delay(uint32_t n){
uint32_t start = systick_count;
while (systick_count - start < n);
return;
}
But somehow, inside the interrupt handler of the RTC it doesn't work. So I replaced my delay function with this one, not using the SysTick:
for (; i>0; i--) {
for (int j = 0; j < 72; ++j) {
__asm__ __volatile__("nop\n\t":::"memory");
}
}
and now everything works just fine.
I'm trying to understand, why the SysTick
apparently doesn't work inside the RTC interrupt handler.
I figured that maybe it's caused by the Interrupt priorities, but according to the datasheet, by default the SysTick Interrupt
's priority is higher than the RTC interrupts priority.
Maybe someone can explain, why this happens?
EDIT1: Ok, so I’ve read a bit more about the interrupt priorities, and it seems that i need to configure the NVIC_IRQChannelPreemptionPriority correctly. I’ll try this as soon as I can...
With regard to the delay inside the interrupt, I know that's not the right way to do It, but I still wanted to understand the program's behaviour
EDIT2: I just tried changing the interrupt priorities in the following way:
// set RTC interrupt priority to 15 (lowest)
NVIC_SetPriority(RTC_IRQn, 15);
// set interrupt priority of SysTick to 0 (highest)
NVIC_SetPriority(SysTick_IRQn, 0);
and now the SysTick delay works within the RTC interrupt handler.