2014-01-08 07:06 AM
Hi
I'm working on a project where I use a interrupt from the RTC. This is the one second interrupt. I also use a couple of other interrupts, for example timer 3. The RTC interrup can have the lowest interrupt possible because i'ts not more than a led that switches on and off. So I set it like this: NVIC_InitTypeDef NVIC_InitStructure; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); RTC_ClearITPendingBit(RTC_IT_SEC); RTC_ITConfig(RTC_IT_SEC, ENABLE); // Enables second interruptTimer 3 has to one of the highest priority interrupt so i set it like this: NVIC_InitTypeDef NVIC_InitStructure; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);But when i use timer 3 to blink a led, I can see that this blinking is interrupted by the one second interrupt from the RTC. If I disable the second interrupt the timer 3 led is blinking as it should do.Am I doing something wrong, or am I missing something?my sincerly Michel2014-01-08 07:37 AM
Hi
'NVIC_IRQChannelPreemptionPriority' should be different values for each IRQ. 0 being the highest priority. Arrange the IRQ priority in order of importance.2014-01-08 07:40 AM
Thanks for your reply.
But the priority groups are different, so the preemption value should not mather right?2014-01-08 07:44 AM
Hi
''But the priority groups are different, so the preemption value should not mather right?'' No, it does matter! You are telling the NVIC what IRQ priority to set for each ISR. If you set everything at 0 - every IRQ is at highest priority and then it is down to pot luck which ISR gets called.2014-01-08 08:01 AM
Hi thanks again for your quick reply. I'm aware of the fact that if two interrupts with the same priority will distort each other. But I was reading about the priority group config with this command:
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
and for the RTCNVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
So what happens with this function?2014-01-08 08:26 AM
Hmmm
Im starting not to like you (asking me hard questions like that!) OK, you have to go to the ARM M4 reference manual to understand IRQ groups. It is complicated. IRQs are linked to their source via the Vector table (ie USART IRQ is always at a fixed location in the Vector table). Some IRQs can have their priority configured, some cannot - see the ARM ref manual. If you set IRQs at the same level - they are grouped together. Then the subpriority is used to determine IRQ trigger order. This is for systems that have so many IRQs, and not enough IRQ priority levels. This allows a system to sub-divide a priority level. So if you set all the IRQ to different priorities - the grouping should not matter. Keep it simple - you are only dealing with 2/3IRQs - just use the priority levels. Do not group them.2014-01-08 10:33 AM
NVIC_PriorityGroupConfig();
Has GLOBAL scope, it does not associated with the individual NVIC_Init() usages.2014-01-09 12:02 AM
But when i use timer 3 to blink a led, I can see that this blinking is interrupted by the one second interrupt from the RTC. If I disable the second interrupt the timer 3 led is blinking as it should do.
I suspect you problem is not associated with interrupt priorities. If you stick to the recommendations, interrupt-induced jitter to your LED toggle should be a few microseconds, or less. Unless you do some heavy-lifting in interrupt handlers, or call routines that rely on other interrupts, or do extensive waits/busy-waits. Or, you do unsynchronized accesses to the LED-GPIO from within your interrupt routines. My gess is, your RTC interrupt calls some routine(s) to output/save a time stamp, which in turn relies on other interrupts ...
2014-01-10 02:47 AM
Hi guys
I want to thank you for your replies. I found the problem in my program. I was completely misunderstanding the use of priority group config. I now see that it is just a setting that you set once, to divide the interrupts. If anybody else encounters this problem. I found this site to be very helpfull: Thanks a lot!