原创 STM32 NVIC 初始化函数,非使用STM32库方式。

2008-8-26 15:12 6814 6 6 分类: MCU/ 嵌入式

//=========================================================================
//         NVIC_enableISR(unsigned isr)
//=========================================================================
void STM32_NVIC_enableISR(unsigned isr)
{
 /* The isr argument is the number of the interrupt to enable. */
 STM32_Nvic_Regs->Enable[ (isr/32) ].all = 1<<(isr % 32);
 
}


//=========================================================================
//         NVIC_Configuration(void)
//=========================================================================
void STM32_NVIC_Configuration(void)
{


#ifdef  VECT_TAB_RAM
   /* Set the Vector Table base location at 0x20000000 */ 
   STM32_Scb_Regs->ExceptionTableOffset.all=0x20000000;
#else  /* VECT_TAB_FLASH  */
 /* Set the Vector Table base location at 0x08000000 */ 
   STM32_Scb_Regs->ExceptionTableOffset.all=0x08000000;
#endif


   /* Configure the Priority Group to 2 bits */ 
   STM32_Scb_Regs->AIRC.all= ((u32)0x05FA0000)|((u32)0x500); //NVIC_PriorityGroup_2(优先级分组)


 /* enabling interrupt  设置TIM2中断优先级,和开中断*/
 STM32_Nvic_Regs->Priority[28].all=0x40;
 STM32_Nvic_Regs->Enable[0].bit.INT28=1;   // IRQ28 默认PRI=35 可设置 TIM2 TIM2全局中断 0x0000_00B0


 /* enabling interrupt  设置TIM3中断优先级,和开中断*/
 STM32_Nvic_Regs->Priority[29].all=0x40;
 STM32_Nvic_Regs->Enable[0].bit.INT29=1;   // IRQ29 默认PRI= 可设置 TIM3 TIM3全局中断 0x0000_00B4



     /* Enable the EXTI3 Interrupt on PD.3 */
 STM32_Nvic_Regs->Priority[9].all=0x40;
 STM32_Nvic_Regs->Enable[0].bit.INT9=1;   // IRQ9  默认PRI=16 可设置 EXTI3 EXTI线3中断 0x0000_0064


     /* Enable the EXTI4 Interrupt on PD.4 */
 STM32_Nvic_Regs->Priority[10].all=0x40;
 STM32_Nvic_Regs->Enable[0].bit.INT10=1;   // IRQ10  默认PRI=17 可设置 EXTI4 EXTI线4中断 0x0000_0068



 /* Configure the SysTick handler priority */
 STM32_Scb_Regs->SystemPriority[11].all=2; //0xE000_ED23 PRI_15 SysTick 的优先级
    
 
}

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
6
关闭 站长推荐上一条 /3 下一条