有没有谁遇到过这样的问题,分享一下解决办法……急。
发送程序是这样子的:
USART_SendData(USART3, ch);
//while (!(USART3->SR & USART_FLAG_TXE));
while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET)
{;}
上面两种等待都用过,都不能解决问题,一开始还工作得好好的,用了一阵子后就出现死在这里的现象。
配置串口程序如下:
void SetupUSART (void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE); //端口B和功能复用功能
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
// Configure USART3 Rx (PB11) as input floating
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //输入浮动状态
GPIO_Init(GPIOB, &GPIO_InitStructure);
// Configure USART3 Tx (PB10) as alternate function push-pull
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用功能开漏输出模式(复用推挽输出)
GPIO_Init(GPIOB, &GPIO_InitStructure);
//通信参数配置
USART_InitStructure.USART_BaudRate = 9600; //9600
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No ;//USART_Parity_Odd
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART3, &USART_InitStructure);
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
USART_Cmd(USART3, ENABLE);
}
|