初级会员
- 积分
- 109
- 金钱
- 109
- 注册时间
- 2013-9-24
- 在线时间
- 4 小时
|
5金钱
求助,FREERTOS下USART3中断工作2小时左右死机,目前是测试程序,就中断接收1个数据,马上发送,请大家帮我看一下串口配置部分是否有问题?
void UART3_Configuration(void)
{
//GPIO端口设置
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
//使能串口3,PB,AFIO总线
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE); //串口时钟配置
USART_DeInit(USART3); //复位串口3
// RS485_CTL3_L(); //RECEIVE
/* B10 USART3_Tx */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //推挽输出-TX
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* B11 USART3_Rx */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入-RX
GPIO_Init(GPIOB, &GPIO_InitStructure);
RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3,ENABLE);//复位串口 3
RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3,DISABLE);//停止复位
USART_InitStructure.USART_BaudRate = 38400;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART3, &USART_InitStructure); //初始化串口
//Usart3 NVIC 配置
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1 ;//抢占优先级1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //子优先级0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
//串口3使用接收中断
USART_ITConfig(USART3,USART_IT_RXNE,ENABLE);
// USART_ITConfig(USART3, USART_IT_TC, ENABLE);
USART_ClearITPendingBit(USART3, USART_IT_TC);
/* Enable the USARTx */
USART_Cmd(USART3, ENABLE);
}
void USART3_IRQHandler(void)
{
u8 uart3_data;
taskENTER_CRITICAL();
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
{
uart3_data =USART_ReceiveData(USART3);//读取接收到的数据
}
taskEXIT_CRITICAL();
}
void USART3_SendChar(u8 ch)
{
u16 i = 0;
USART_SendData(USART3, ch);
while(USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET && i < 3000)
}
|
|