F4 USART3的问题

2019-07-21 03:30发布

今天收到原子的开发板,想做一个,COM1 与PC机连接,COM2和COM3分别把从COM1发过来的数据发出去,但是配置COM3的时候遇到了问题,我程序是定时发5个字节,上位机也能收到,但是字节码都不对的,我发的是  0A 0A 0A 0A FF,但是收到的确是:E0 00 E0 00 E0 00 E0 00 FC,波特率什么的 设置都是对的啊;


void bsp_InitUart(void)
{


USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
//DMA_InitTypeDef DMA_InitStructure;

/* ????GPIO?±?? */
RCC_AHB1PeriphClockCmd(USARTx_TX_GPIO_CLK | USARTx_RX_GPIO_CLK, ENABLE);

/* ????USART?±?? */
USARTx_CLK_INIT(USARTx_CLK, ENABLE);

     //????DMA?±??
   RCC_AHB1PeriphClockCmd(USARTx_DMAx_CLK, ENABLE);


/* ???? USART ?????? AF7 */
GPIO_PinAFConfig(USARTx_TX_GPIO_PORT, USARTx_TX_SOURCE, USARTx_TX_AF);
GPIO_PinAFConfig(USARTx_RX_GPIO_PORT, USARTx_RX_SOURCE, USARTx_RX_AF);

/* ????GPIO */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

GPIO_InitStructure.GPIO_Pin = USARTx_TX_PIN;
GPIO_Init(USARTx_TX_GPIO_PORT, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = USARTx_RX_PIN;
GPIO_Init(USARTx_RX_GPIO_PORT, &GPIO_InitStructure);

USART_OverSampling8Cmd(USARTx, ENABLE);


USART_InitStructure.USART_BaudRate = 9600;
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(USARTx, &USART_InitStructure);

/* Enable USART */
USART_Cmd(USARTx, ENABLE);

/* ???? USART DMA RX ???ó */
USART_DMACmd(USARTx, USART_DMAReq_Rx, ENABLE);

/* ???? USART DMA TX ???ó */
USART_DMACmd(USARTx, USART_DMAReq_Tx, ENABLE);

/* ????·????????ê?????? */
DMA_ITConfig(USARTx_TX_DMA_STREAM, DMA_IT_TC, ENABLE);  
    
    /* ?????????????ê?????? */
DMA_ITConfig(USARTx_RX_DMA_STREAM, DMA_IT_TC, ENABLE);

/* ???? DMA Stream ?????¨?? */
NVIC_InitStructure.NVIC_IRQChannel = USARTx_DMA_TX_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure); 

/* ???? DMA Stream ?????¨?? */
NVIC_InitStructure.NVIC_IRQChannel = USARTx_DMA_RX_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。