高级会员

- 积分
- 810
- 金钱
- 810
- 注册时间
- 2014-5-30
- 在线时间
- 93 小时
|
1金钱
本帖最后由 天山狐狸 于 2016-1-28 22:07 编辑
如题,我使用了407的6个串口,用外设库初始化的,但是现在1通,3、6不通,2、4、5还没有测试。
代码如下,串口1、3、6的代码基本相同,只是USARTx不通而已。6个串口的管脚分配是软件STM32CubeMX生成的。
[mw_shl_code=applescript,true]void USART1_Init(uint32_t BaudRate)
{
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = 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(USART1, &USART_InitStructure);//初始化串口
USART_Cmd(USART1, ENABLE);//使能串口
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//开相关中断
}
void USART3_Init(uint32_t BaudRate)
{
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = 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(USART3, &USART_InitStructure);//初始化串口
USART_Cmd(USART3, ENABLE);//使能串口
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);//开相关中断
}[/mw_shl_code]
|
最佳答案
查看完整内容[请看2#楼]
最好有个发送完成中断和发送缓存为空中断,在那里将485收发控制脚切换为接收模式即可,在发送函数里切换显然是不正确的,你只是把数据给了发送缓存,但实际不一定发送完成的,就正如你的波形一下!
|