cancel
Showing results for 
Search instead for 
Did you mean: 

Is my understanding of NVIC is correct?

bluewaters213
Associate III
Posted on July 31, 2013 at 22:17

Hello,

I don't know if my understanding of NVIC is correct especially to System Tick Timer.

&sharpinclude ''stm32f10x.h''

void NVIC_Configuration(void)

 {

    

     uint32_t priorityGroup;                              /* Variables to store priority group and priority */

     uint32_t priority;    

    

     NVIC_SetPriorityGrouping(1);                         /* 1 bits for pre-emption priority, 3 bits for subpriority */

   priorityGroup =  NVIC_GetPriorityGrouping();         /* Get used priority grouping */

    

   priority = NVIC_EncodePriority(priorityGroup, 1, 3); /* Encode priority with 3 for subpriority and 1 for preempt priority    */

   NVIC_SetPriority(ADC1_2_IRQn, priority);             /* Set new ADC1_2_IRQn priority */

   NVIC_EnableIRQ(ADC1_2_IRQn);                         /* Enable ADC Interrupt */

    

     priority = NVIC_EncodePriority(priorityGroup, 1, 1); /* Encode priority with 1 for subpriority and 1 for preempt priority    */

   NVIC_SetPriority(TIM1_CC_IRQn, priority);            /* Set new TIM1_CC_IRQn priority */    

     NVIC_EnableIRQ(TIM1_CC_IRQn);                        /* Enable Timer1 CC4 Interrupt */    

     priority = NVIC_EncodePriority(priorityGroup, 1, 2); /* Encode priority with 2 for subpriority and 1 for preempt priority    */

   NVIC_SetPriority(TIM2_IRQn, priority);               /* Set new TIM2_IRQn priority */    

     NVIC_EnableIRQ(TIM2_IRQn);                           /* Enable Timer1 CC4 Interrupt */

    

     /* TIM4_IRQn should preempt all other interrupt (Highest Priority)*/

     priority = NVIC_EncodePriority(priorityGroup, 0, 0); /* Encode priority with 0 for subpriority and 0 for preempt priority    */

   NVIC_SetPriority(TIM4_IRQn, priority);               /* Set new TIM4_IRQn priority */    

     NVIC_EnableIRQ(TIM4_IRQn);                           /* Enable Timer1 CC4 Interrupt */

//NB: My main code does not work if I include the below section and Systick_Configuration(void) in main

//Systick interrupt does nothing in my main code. Adding or Removing Systick interrupt supposed not to affect it

//functionality.I just wanted to test my understanding of NVIC

  /* SysTick_IRQn lowest Priority */

     priority = NVIC_EncodePriority(priorityGroup, 1, 6); /* Encode priority with 6 for subpriority and 1 for preempt priority    */

   NVIC_SetPriority(SysTick_IRQn, priority);            /* Set new SysTick_IRQn priority */    

     NVIC_EnableIRQ(SysTick_IRQn);                        /* Enable SysTick_IRQn Interrupt */

      

 }

void Systick_Configuration(void)

    {

        

        if (SysTick_Config(SystemCoreClock / 1000))     //2KHz

        {

        /* Capture error */

        while (1);

        }

    

    }

void SysTick_Handler(void)

 {

    GPIOB->ODR ^= (1 << 8);

 }

 

int main(void)

{

      Systick_Configuration();

    

    NVIC_Configuration();  

    

        RCC_Configuration();                          //Configure System Peripherals Clock

    

        GPIO_Configuration();                         //Configure Input & Output Pins

          

      ADC1_2_Configuration();                       //Configure ADC1_2 in Dual Simultanous Sampling on a Single Channel

    

      PWM_Configuration();                          //Configure Timer1 for 25KHz Independent Complementary PWM

    TIM4_Configuration();

    

      TIM3_Configuration();                         //Configure & Start Timer3 for Alignment and StartUp Phase

    

    TIM2_Configuration();    

    

      StartMotor();                                 //Start Motor

          

        while(1)

        {

     //Configure USART to Send and Receive Important Motor Details

        }

}

#nvic #stm32
2 REPLIES 2
Posted on July 31, 2013 at 23:35

Mostly, but you can't enable it as an ''IRQ'' because it's technically a system handler.

NVIC_EnableIRQ(SysTick_IRQn); // CAN'T DO THIS
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
bluewaters213
Associate III
Posted on August 01, 2013 at 00:57

Hello,

Thanks..My code is functioning with SysTick_IRQn enable. Your correction was right.I shouldn't have re-enable SysTick_IRQn.

Regards