我主程序就是1号灯的200ms闪烁,usart2串口中断,中断程序是2号灯的反转。正常现象应该是1号灯闪烁,然后我发送个串口数据,然后2号灯反转一下,以此循环。 但是实际现象是,我没发送串口数据时,1号灯200ms闪烁,当我发送一个串口数据时,1号灯不闪了,2号灯也没反应。然后不论怎样,2个灯都不变了。 这是一个很简单的程序,大神估计看一下就能知道我哪错了,但是我找了好几天了啊,一直单步也找不到,拜托了!
[mw_shl_code=c,true]int main(void)
{
OS_ERR err;
BSP_IntInit ();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
CPU_Init();
Mem_Init();
BSP_IntDisAll();
OSInit(&err);
/*---------------------Init uC/OS-III---------------------------*/
OSTaskCreate((OS_TCB *)&AppTaskStartTCB,
(CPU_CHAR *)"App Task Start",
(OS_TASK_PTR )AppTaskStart,
(void *)0u,
(OS_PRIO )APP_CFG_TASK_START_PRIO,
(CPU_STK *)&AppTaskStartStk[0u],
(CPU_STK_SIZE )AppTaskStartStk[APP_CFG_TASK_START_STK_SIZE / 10u],
(CPU_STK_SIZE )APP_CFG_TASK_START_STK_SIZE,
(OS_MSG_QTY )0u,
(OS_TICK )0u,
(void *)0u,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
void uart_init(void);
uart_init();
OSStart(&err);
while (DEF_ON) {
};
}
void uart_init(void){
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
USART_DeInit(USART2);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_USART2);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource6, GPIO_AF_USART2);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART2, &USART_InitStructure);
/*---------------------interrupt初始化---------------------------*/
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
void USART2_IRQHandler(void);
BSP_IntVectSet(BSP_INT_ID_USART2, USART2_IRQHandler);
BSP_IntPrioSet(BSP_INT_ID_USART2,2u);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
USART_Cmd(USART2, ENABLE);
}
/*---------------------中断程序---------------------------*/
void USART2_IRQHandler(void)
{
unsigned char ch;
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
{
USART_ClearFlag(USART2,USART_FLAG_RXNE);
USART_ClearITPendingBit(USART2,USART_IT_RXNE);
ch = USART_ReceiveData(USART2);
BSP_LED_Toggle(2u);
}
}
static void AppTaskStart (void *p_arg)
{
OS_ERR err;
(void)p_arg;
BSP_Init();
BSP_Tick_Init();
BSP_LED_Off(0u);
while (DEF_TRUE) {
BSP_LED_Toggle(1u);
OSTimeDlyHMSM(0u, 0u, 0u, 200u,
OS_OPT_TIME_HMSM_STRICT,
&err);
}
}[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>