cancel
Showing results for 
Search instead for 
Did you mean: 

Interrupt priority problem

m_
Associate II
Posted on January 08, 2014 at 16:06

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 interrupt

Timer 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

Michel
8 REPLIES 8
chen
Associate II
Posted on January 08, 2014 at 16:37

Hi

'NVIC_IRQChannelPreemptionPriority'  should be different values for each IRQ.

0 being the highest priority.

Arrange the IRQ priority in order of importance.

m_
Associate II
Posted on January 08, 2014 at 16:40

Thanks for your reply.

But the priority groups are different, so the preemption value should not mather right?

chen
Associate II
Posted on January 08, 2014 at 16:44

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.

m_
Associate II
Posted on January 08, 2014 at 17:01

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 RTC

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);

So what happens with this function?

chen
Associate II
Posted on January 08, 2014 at 17:26

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.

Posted on January 08, 2014 at 19:33

NVIC_PriorityGroupConfig();

Has GLOBAL scope, it does not associated with the individual NVIC_Init() usages.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
frankmeyer9
Associate II
Posted on January 09, 2014 at 09:02

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 ...

m_
Associate II
Posted on January 10, 2014 at 11:47

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: 

http://micromouseusa.com/?p=279

Thanks a lot!