打印

STM32固件库NVIC疑问

[复制链接]
3939|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
auzxj|  楼主 | 2009-8-21 17:27 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
固件库中有这么一段:
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the Priority Grouping with 1 bit */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* Enable TIM3 global interrupt with Preemption Priority 0 and Sub
Priority as 2 */
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitStructure(&NVIC_InitStructure);
/* Enable USART1 global interrupt with Preemption Priority 1 and Sub
Priority as 5 */
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 5;
NVIC_InitStructure(&NVIC_InitStructure);
/* Enable RTC global interrupt with Preemption Priority 1 and Sub
Priority as 7 */
NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 7;
NVIC_InitStructure(&NVIC_InitStructure);
/* Enable EXTI4 interrupt with Preemption Priority 1 and Sub
Priority as 7 */
NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 7;
NVIC_InitStructure(&NVIC_InitStructure);
/* TIM3 interrupt priority is higher than USART1, RTC and EXTI4
interrupts priorities. USART1 interrupt priority is higher than RTC
and EXTI4 interrupts priorities. RTC interrupt priority is higher
than EXTI4 interrupt prioriy. */

问题:
RTC,EXTI4的NVIC_IRQChannelPreemptionPriority和NVIC_IRQChannelCmd为什么没有设置
沙发
香水城| | 2009-8-21 17:40 | 只看该作者
在设置RTC和EXTI4的NVIC之前,已经设置了USART1的参数:

NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 5;
NVIC_InitStructure(&NVIC_InitStructure);

这里已经设置了NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1,在函数NVIC_InitStructure中并没有改变这个变量的数值,所以随后的RTC和EXTI4部分省略了一条语句。

我不认为这是一个好的办法,因为它减低了程序的可读性和可移植性,却可以减小程序代码量,但是不推荐大家这样做,除非你非常清楚你在做什么。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:當我不如意時.我掏出小JJ.凝視靜思他所蘊涵的精神-能長能短.能粗能細.能曲能伸.能軟能硬.那困難還算個鳥?

629

主题

1625

帖子

1

粉丝