3个中断(adc、外部IO、定时器)
单独都可以进中断(各自中断已配置好)(板子外部一直满足ADC和IO中断的发生条件、定时器内部自动产生),但三个中断在一个工程里则只能
进ADC和外部IO,进不去定时器中断
问:怎么能3个中断都进去?(优先级无所谓)
附:中断优先级分组2
法1:定时器抢占0、响应子0-----------文件是IO_Digital.c
ADC 抢占1、响应子1------------------------------------文件是adc.c
外部IO 抢占2、响应子2-------------------------------------文件是timer.c
法2:定时器抢占0、响应子0-----------
ADC 抢占2、响应子2
外部IO 抢占1、响应子1
法3:定时器抢占0、响应子0-----------
ADC 抢占1、响应子0
外部IO 抢占1、响应子1
3种情况结果都是只能进ADC和外部IO,进不去定时器中断
板子:STM32F4
库函数
TIMER
NVIC_InitStructure.NVIC_IRQChannel=TIM3_IRQn; //定时器3中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0; //抢占优先级2>ADC采集中断优先级
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0; //子优先级1
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
adc
NVIC_InitStructure.NVIC_IRQChannel = ADC_IRQn; //中断通道ADC
//抢占优先级高的中断可以打断抢占优先级低的中断;抢占优先级相同时比较响应优先级(子优先级)。
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //2
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
外部IO
NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; //1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
我来回答
收藏转载
|