打印

用STM32的串口3通信

[复制链接]
362|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
一亚麻怡|  楼主 | 2018-6-29 13:28 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
大神们,我写的用串口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)        ;

}

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

使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

404

主题

404

帖子

0

粉丝