STM32 串口3 USART3 速度不正确,数据是错误的

我USART3全映射到PD8 PD9上面,可以发送数据也可以接收数据,但是感觉波特率是不正确的,数据全是错误的下面是程序,不知道是不是不能用函数库初始化,有过经验的朋友们肯请你们帮忙一下,先放谢过

void USART3_config(void)
{
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = 19200;
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_ITConfig(USART3, USART_IT_RXNE, ENABLE);
USART_Cmd(USART3, ENABLE);
}

上面是初始化程序,用232模块还有485模块都试过,数据都是有问题的,但是可以正常进行中断处理,是否波特率不应该这样设置,请求帮助

我觉得可能不是配置的问题可能是你发送函数写的有问题  我的代码是ok的

void USART3_Configuration(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    USART_InitTypeDef USART_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStructure;

//使能串口3,PB,AFIO总线
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE); //串口时钟配置


    GPIO_InitStructure.GPIO_Pin  =  GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_Out_PP; //开漏输出
GPIO_InitStructure.GPIO_Speed  = GPIO_Speed_50MHz; //50M时钟速度
GPIO_Init(GPIOB, &GPIO_InitStructure);

RS485_CTL3_L();  //RECEIVE


    /* B10 USART3_Tx */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //推挽输出-TX
    GPIO_Init(GPIOB, &GPIO_InitStructure);

    /* B11 USART3_Rx  */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入-RX
    GPIO_Init(GPIOB, &GPIO_InitStructure);


    USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
USART_ClockInit(USART3, &USART_ClockInitStructure);
    USART_Init(USART3, &USART_InitStructure);

    /* Enable the USARTx */
    USART_Cmd(USART3, ENABLE);

//串口3使用接收中断
USART_ITConfig(USART3,USART_IT_RXNE,ENABLE);
}
/**************************************************************************************
* 名    称: 
* 功    能: 
* 参    数: 
* 返 回 值: 
*
* 修改历史:
*   版本    日期     作者     
**************************************************************************************/
void USART3_Putc(unsigned char c)
{
     RS485_CTL3_H();  //SEND
SysTickDelay(1); 
USART_SendData(USART3, c);
    while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET );
SysTickDelay(1); 
RS485_CTL3_L();  //RCV
}

温馨提示:内容为网友见解,仅供参考
第1个回答  2013-09-01
这个一其实简单,你要保证PC与MCU两个设置的通信参数一样就OK了,你这个程序是人家写好的,是没有什么问题的。这样就是PC这边的UART参数设置与MCU不一样。
相似回答