新手上路
- 积分
- 33
- 金钱
- 33
- 注册时间
- 2018-5-24
- 在线时间
- 8 小时
|
1金钱
使用的板子是正点原子的开发板
初始化usart3的代码如下:
void uart3_init(u32 bound)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO, ENABLE);
GPIO_PinRemapConfig(GPIO_PartialRemap_USART3, ENABLE);
//USART3_TX GPIOC.10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
//USART3_RX GPIOC.113õê¼»ˉ
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOC, &GPIO_InitStructure);
//Usart NVIC ÅäÖÃ
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//USART 3õê¼»ˉéèÖÃ
USART_InitStructure.USART_BaudRate = bound;//′®¿ú2¨ìØÂê
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//×Ö3¤Îa8λêy¾Y¸ñê½
USART_InitStructure.USART_StopBits = USART_StopBits_1;//ò»¸öí£Ö1λ
USART_InitStructure.USART_Parity = USART_Parity_No;//ÎTÆæÅ¼D£Ñéλ
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//ÎTó2¼têy¾Yá÷¿ØÖÆ
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //êÕ·¢Ä£ê½
USART_Init(USART3, &USART_InitStructure); //3õê¼»ˉ′®¿ú3
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);//¿aÆô′®¿ú½óêüÖD¶Ï
USART_Cmd(USART3, ENABLE); //ê1Äü′®¿ú
}
初始化:
uart3_init(115200);
但查看usart3时看到的波特率是115384,如下图:
只有降频后波特率才是自己设置的值。
另外串口发送代码如下:
USART_SendData(USART3, 0x5A);
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);
USART_SendData(USART3, 0xA5);
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);
但在上位机用串口工具看到的值是:0x29 0x2D
RS232,波特率匹配
有人知道设置波特率115200为什么会出错吗,是不是usart3不支持这个频率(其中usart1是可以的),另外发送的是乱码有人知道怎么回事吗?
|
-
|