论坛元老
 
- 积分
- 7464
- 金钱
- 7464
- 注册时间
- 2015-1-15
- 在线时间
- 1368 小时
|
发表于 2020-4-16 19:28:34
|
显示全部楼层
问题挺多:
1、引脚初始化问题
GPIO_InitStructure.GPIO_Pin = USART_Tx_Pin;
GPIO_InitStructure.GPIO_Pin = USART_Rx_Pin;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(USART_Tx_GPIO, &GPIO_InitStructure);
GPIO_Init(USART_Rx_GPIO, &GPIO_InitStructure);
这里发送引脚就没有设置成功
//
//发送管脚 PA.02
//接收管脚 PA.03
//
GPIO_InitStructure.GPIO_Pin = USART_Tx_Pin;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(USART_Tx_GPIO, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = USART_Rx_Pin;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(USART_Rx_GPIO, &GPIO_InitStructure);
改成这样就可以了
2、发送中断使能类型
if (xTxEnable) //发送使能
{
USART_ITConfig(USE_USART, USART_IT_TXE, ENABLE); //使能
//GPIO_SetBits(GPIOD, GPIO_Pin_4); //发送
}
else //失能
{
USART_ITConfig(USE_USART, USART_IT_TXE, DISABLE); //失能
//GPIO_ResetBits(GPIOD, GPIO_Pin_4); //设置接收
}
更改为
if (xTxEnable) //发送使能
{
USART_ITConfig(USE_USART, USART_IT_TC, ENABLE); //使能
//GPIO_SetBits(GPIOD, GPIO_Pin_4); //发送
}
else //失能
{
USART_ITConfig(USE_USART, USART_IT_TC, DISABLE); //失能
//GPIO_ResetBits(GPIOD, GPIO_Pin_4); //设置接收
}
|
|