新手上路
- 积分
- 37
- 金钱
- 37
- 注册时间
- 2016-2-29
- 在线时间
- 7 小时
|
3金钱
有一个STM32F103下位机,串口3每隔一分钟向上位机发送数据。上位机使用的是正点原子的XCOM2.0.一般情况一切正常。
如果windows休眠,XCOM串口助手就会崩溃。同时stm32也会“死机”。ucosiii的各个任务都不会运行了。
猜测有可能是串口的发送卡死。求解决方案。,
串口3的配置
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_Init(dbgUSART_TX_PORT,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Init(dbgUSART_RX_PORT,&GPIO_InitStructure);
USART_InitStructure.USART_BaudRate=115200;
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(USART3,&USART_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel=USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=3;
NVIC_Init(&NVIC_InitStructure);
USART_ITConfig(USART3,USART_IT_RXNE,ENABLE);
USART_Cmd(dbgUSARTx,ENABLE);
串口3 的接受没有写。
void USART3_IRQHandler{}
串口3的发送函数
发送字节
void u3SendByte(u8 byte)
{
USART_SendData(USART3,(uint8_t)byte);
while(USART_GetFlagStatus(USART3,USART_FLAG_TXE)==RESET);
}
发送字符串使用的是printf,为此使用了microLib库
实现了putc函数
int fputc(int ch,FILE*f)
{
USART_SendData(USART3,(uint8_t)ch);
while(USART_GetFlagStatus(USART3,USART_FLAG_TXE)==RESET)
;
return ch;
}
|
|