大神们,我写的用串口3进行通信的代码是这样的:
void RCC_Configuration(void)
{
SystemInit();
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO,ENABLE); //开启端口B和AFIO时钟
RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART3 , ENABLE); //UART3时钟开启
GPIO_PinRemapConfig(GPIO_PartialRemap_USART3,ENABLE); //重映射
}
void USART3_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
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(USART3, &USART_InitStructure);
USART_Cmd(USART3, ENABLE);
}
void uart3_send(char *buf)
{
USART3->SR;
while(*buf!='\0')
{
USART_SendData(USART3, *buf++);
while (USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET);
}
int main()
{
RCC_Configuration();
USART3_Config();
uart3_send("abc");
while(1) ;
}
一直发不出去,是乍回事呢???求解答!!! |