AnsweredAssumed Answered

Is my understanding of NVIC is correct?

Question asked by slimsly on Jul 31, 2013
Latest reply on Aug 1, 2013 by slimsly
Hello,

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

#include "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
        }
}

Outcomes