Skip to main content
ebast
Associate II
December 11, 2018
Solved

NVIC_Init() library function does not work as expected

  • December 11, 2018
  • 2 replies
  • 1440 views

Hi All,

I have simple code to assign preemption priority and subpriority. I have tested this code on the stm32f103. Even if i set the preemption priority and subpriority, when I read the priority it returns as 0x00.

According to the information from STM32 datasheet the priority register is 0xe000e40e ( NVIC channel 14 belongs to DMA1_Channel4 interrupts).

And I could read 0x00 from that register after NVIC was initialized. It means NVIC channel #14 has the highest priority in the system.

I do not understand that way library function does not work as expected. Do you have any suggestion?

 NVIC_InitTypeDef NVIC_InitStructure;
 
 /* DMA1 Channel4 interrupt setting */
 NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel4_IRQn;
 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 11;
 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 11;
 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
 NVIC_Init(&NVIC_InitStructure);
 /* -- */ 
 priority = NVIC_GetPriority(DMA1_Channel4_IRQn);
 /* -- */ 
 tprintf("\r\nNVIC->IP[DMA1_Channel4_IRQn]=0x%x", NVIC->IP[DMA1_Channel4_IRQn]); 
 tprintf("\r\npriority= %d ",priority);

The output of the program is:

NVIC->IP[DMA1_Channel4_IRQn]=0x0
priority= 0 

This topic has been closed for replies.
Best answer by Tesla DeLorean

>> Do you have any suggestion?

Yes, review the group settings of the NVIC, and try setting 1,1

There are only 4-bits to describe *both* Preemption and SubPriorities, setting both to 11 seems to be a bad plan.

2 replies

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
December 11, 2018

>> Do you have any suggestion?

Yes, review the group settings of the NVIC, and try setting 1,1

There are only 4-bits to describe *both* Preemption and SubPriorities, setting both to 11 seems to be a bad plan.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
ebast
ebastAuthor
Associate II
December 12, 2018

It is solved thank you.