在做今年的电子设计,需要用到串口中断、定时器2和定时器7中断,具体操作如下:
1.串口用来发送命令和接收回传数据;(与电机驱动进行同行用)
2.定时器2用来定时得到旋转编码器的脉冲数;
3.定时器用来检测按键(K60里边的那个按键的长按、短按等);
NVIC配置如下:
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
/* USART2 */
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Timer2 */
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Timer7 */
NVIC_InitStructure.NVIC_IRQChannel = TIM7_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
定时器2为5ms中断,定时器7为10ms中断;
问题如下:
由于旋转编码器的脉冲数由串口获得,通过定时器2中断进行数据读取时,会造成串口不能进行数据的发送,不知道这中间出了什么问题? |