金牌会员
 
- 积分
- 1148
- 金钱
- 1148
- 注册时间
- 2019-9-9
- 在线时间
- 171 小时
|

楼主 |
发表于 2019-12-20 15:29:09
|
显示全部楼层
我在发送前判断TXE标志位,串口助手上就没有显示了。
我尝试使用printf打印输出
int main(void)
{
USART_Config();
while(1)
{
printf( "22 \n");
printf( "33 \n");
}
}
其他相关配置:
UART相关的配置:
void USART_Config(void)
{ GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure;
DEBUG_USART_GPIO_APBxClkCmd(DEBUG_USART_GPIO_CLK, ENABLE);
DEBUG_USART_APBxClkCmd(DEBUG_USART_CLK, ENABLE);
GPIO_InitStructure.GPIO_Pin = DEBUG_USART_TX_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(DEBUG_USART_TX_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = DEBUG_USART_RX_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(DEBUG_USART_RX_GPIO_PORT, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = DEBUG_USART_BAUDRATE;
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(DEBUG_USARTx, &USART_InitStructure);
NVIC_Configuration();
USART_ITConfig(DEBUG_USARTx, USART_IT_RXNE, ENABLE);
USART_Cmd(DEBUG_USARTx, ENABLE);
USART_ClearFlag(USART1, USART_FLAG_TC);
}
/// 重定向C库函数printf到USART2
int fputc(int ch, FILE *f)
{
DEBUG_USARTx->SR;
USART_SendData(DEBUG_USARTx, (uint8_t) ch);
while (USART_GetFlagStatus(DEBUG_USARTx, USART_FLAG_TXE)== RESET);
return (ch);
}
串口助手可以正常显示一部分后乱码,然后就没有数据传输,需要重新断电后,传输部分数据,乱码,...
|
-
|