我跑裸机的时候在中断里面接收到数据就马上发送出来没有问题,但是在Ucos系统下只有第一次进了UART中断服务程序,ucos其它任务照常运行。这是怎么回事?(备注:接收的是GPS模块传过来的数据,然后在任务中串口输出是没问题的,就是中断接收有问题)
中断服务程序如下:
void USART1_IRQHandler(void)
{
INT8U i = 0;
OS_CPU_SR cpu_sr;
OS_ENTER_CRI
tiCAL();
OSIntNesting++;
OS_EXIT_CRITICAL();
while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET)
{
}
i = USART_ReceiveData(USART1);
printf("%c",i);
OSIntExit();
}
初始化那些应该没问题,跑裸机是可以的
下面是初始化程序:
void NvicInit(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0x03;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void UartInit(void)
{
INT8U i;
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA , ENABLE); // 使能GPIOA端口
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 , ENABLE); // 使能串口1时钟
GPIO_PinAFConfig(GPIOA ,GPIO_PinSource9, GPIO_AF_1);
GPIO_PinAFConfig(GPIOA ,GPIO_Pin_10, GPIO_AF_1);
/////////////////////////////////////////////////////////////////////////////////////
/* PA9==TX PA10-RX */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 ;
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_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA , &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(USART1, &USART_InitStructure); //串口配置
USART_ITConfig(USART1, USART_IT_RXNE,ENABLE);//打开中断
USART_Cmd(USART1, ENABLE);//使能串口1
USART_ClearFlag(USART1, USART_FLAG_TC);
}
一周热门 更多>