野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 17016|回复: 2

用STM32的串口3通信

[复制链接]
发表于 2014-7-26 20:57:07 | 显示全部楼层 |阅读模式
大神们,我写的用串口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)        ;

}

一直发不出去,是乍回事呢???求解答!!!
回复

使用道具 举报

发表于 2014-7-26 21:28:48 | 显示全部楼层
如果引脚没有选错,程序看不出有问题,看看板子有没引脚共用了
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-7-26 21:30:43 | 显示全部楼层
伯思美 发表于 2014-7-26 21:28
如果引脚没有选错,程序看不出有问题,看看板子有没引脚共用了

刚测试了下,原来是引脚和引出的排针没连上,焊接好就没问题了。。。坑啊!!!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-9-22 07:34 , Processed in 0.037762 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表