打印

求助!stm32f407 串口配置

[复制链接]
178|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
没名字的人|  楼主 | 2018-7-31 13:40 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
初次使用stm32的串口,参照网上找到的f1的例程改了改用在f4上。可是从超级终端上看就是没有收到数据。是我配置的有问题么?用的是usart3,配置文件如下:

void USART_RCC_Configuration(void)
{
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
}

void USART_GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  
  GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9;
  GPIO_Init(GPIOD, &GPIO_InitStructure);
  
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_USART3);
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_USART3);
}

void USART_Configuration(void)
{
  USART_InitTypeDef USART_InitStruct;
  
  USART_RCC_Configuration();
  
  USART_InitStruct.USART_BaudRate = 115200;
  USART_InitStruct.USART_StopBits = USART_StopBits_1;
  USART_InitStruct.USART_WordLength = USART_WordLength_8b;
  USART_InitStruct.USART_Parity = USART_Parity_No;
  USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStruct.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
  
  USART_Init(USART3, &USART_InitStruct);
  USART_ITConfig(USART3,USART_IT_RXNE,ENABLE);
  USART_Cmd(USART3, ENABLE);
  
  USART_GPIO_Configuration();
}

主程序:
int main(void)
{
    SystemInit();
    USART_Configuration();
    printf("x0c");printf("x0c");
    printf("33[1;40;32m");
    printf("
*******************************************************************************");
    printf("
************************ Copyright 2009-2012, ViewTool ************************");
    printf("
*************************** http://www.viewtool.com ***************************");
    printf("
***************************** All Rights Reserved *****************************");
    printf("
*******************************************************************************");
    printf("
");
    while(1)
    {
            
        if(USART_GetFlagStatus(USART3, USART_IT_RXNE) != RESET)
        {
        printf("%c",USART_ReceiveData(USART3));
        }

    }
}
还请各位指导!

使用特权

评论回复

相关帖子

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

本版积分规则

420

主题

432

帖子

0

粉丝