NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the NVIC Preemption Priority Bits */
/* Configure one bit for preemption priority */
/* 優先級組說明了搶佔優先級所用的位數,和子優先級所用的位數 在這裏是1, 7 */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
/* Enable the USART1 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn; //設置串口5中斷
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //搶佔優先級 0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //子優先級爲0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能
NVIC_Init(&NVIC_InitStructure);
其中IRQChannel在stm32f2xx.h中查找。UART5_IRQn爲UART5中斷通道。