这两天在写串口通讯,首先进行的是单字节的数据发送,以下是我的函数:
void Usart_GPIO_Config()
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //0x01
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //0x02
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
void Usart_InitConfig()
{
USART_ClockInitTypeDef USART_ClockInitStructure;
USART_InitTypeDef USART_InitStructure;
Usart_GPIO_Config();
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;
/* Configure the USART3 synchronous paramters */
USART_ClockInit(USART3, &USART_ClockInitStructure);
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;
/* Configure USART3 basic and asynchronous paramters */
USART_Init(USART3, &USART_InitStructure);
/* Enable USART3 */
USART_Cmd(USART3, ENABLE);
}
void Usart()
{
Usart_RCC_Config();
Usart_InitConfig();
while(1)
{
USART_SendData(USART3,0x0062);
while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
while(USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == RESET)
DataToRead = USART_ReceiveData(USART3);
}
}
上面是GPIO口和串口设置,但是程序调试串口没有数据发送出来,一直在发送中等待,请教各位帮忙看看代码,是不是我的串口配置有问题?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
本论坛就有.2楼设计过一款407的开发板呢.
---------------------------------
看到了,现在串口已经通了,原来是我自己的时钟设置有问题。串口是通了,不过收发数据还是有点小问题,我继续学习中
一周热门 更多>