打印
[AT32F403/403A]

请教AT34F403 串口4配置问题

[复制链接]
647|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
fyp5593|  楼主 | 2021-4-1 12:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
请教大神,调了好久的串口4一直没调好,我跟串口5一样的配置,串口5可以,4 死活不行,感觉跟那个引脚有关,就是不知道在哪配置
/*U4复用*/
void UART4__Init(void)
{

  GPIO_InitType GPIO_InitStructure;
  USART_InitType USART_InitStructure;

  /*Enable the UART Clock*/
  RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_GPIOA, ENABLE);       
  RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_UART4, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_AFIO, ENABLE);

  GPIO_PinsRemapConfig(AFIO_MAP6_UART4_0001, ENABLE);

  /* Configure the UART4 TX pin */
  GPIO_StructInit(&GPIO_InitStructure);
  GPIO_InitStructure.GPIO_Pins = GPIO_Pins_0;
  GPIO_InitStructure.GPIO_MaxSpeed = GPIO_MaxSpeed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;       
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  /* Configure the UART4 RX pin */
  GPIO_InitStructure.GPIO_Pins = GPIO_Pins_1;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  /*Configure UART param*/
  USART_StructInit(&USART_InitStructure);
  USART_InitStructure.USART_BaudRate = 115200;
  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(UART4, &USART_InitStructure);

  USART_Cmd(UART4, ENABLE);  

}

/*U5复用*/
void UART5__Init(void)
{
  GPIO_InitType GPIO_InitStructure;
  USART_InitType USART_InitStructure;

  /*Enable the UART Clock*/
  RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_GPIOB, ENABLE);       
  RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_UART5, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_AFIO, ENABLE);

  GPIO_PinsRemapConfig(AFIO_MAP5_USART5_0001, ENABLE);

  /* Configure the UART5 TX pin */
  GPIO_StructInit(&GPIO_InitStructure);
  GPIO_InitStructure.GPIO_Pins = GPIO_Pins_9;
  GPIO_InitStructure.GPIO_MaxSpeed = GPIO_MaxSpeed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;       
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  /* Configure the UART5 RX pin */
  GPIO_InitStructure.GPIO_Pins = GPIO_Pins_8;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  /*Configure UART param*/
  USART_StructInit(&USART_InitStructure);
  USART_InitStructure.USART_BaudRate = 115200;
  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(UART5, &USART_InitStructure);

  USART_Cmd(UART5, ENABLE);   
}

使用特权

评论回复
沙发
ArterySW| | 2021-4-1 13:14 | 只看该作者
你的芯片应该是403A吧,所以工程的配置(芯片选择、C\C++ define选择)要选403A,这样的话你会看到403A uart4 的 remap 应该是:AFIO_MAP6_UART4_0010,而不是 AFIO_MAP6_UART4_0001

使用特权

评论回复
板凳
fyp5593|  楼主 | 2021-4-1 13:35 | 只看该作者
ArterySW 发表于 2021-4-1 13:14
你的芯片应该是403A吧,所以工程的配置(芯片选择、C\C++ define选择)要选403A,这样的话你会看到403A uar ...

我用的是keil 5.24,在官方开发板例程的基础上改的,找了下at32f4xx_gpio.h,不管1.1.9还是1.2.4版里面都找不到AFIO_MAP6_UART4_0010 这一条,跟UART4有关的有且只有 AFIO_MAP6_UART4_0001这个

使用特权

评论回复
地板
ArterySW| | 2021-4-1 14:22 | 只看该作者
fyp5593 发表于 2021-4-1 13:35
我用的是keil 5.24,在官方开发板例程的基础上改的,找了下at32f4xx_gpio.h,不管1.1.9还是1.2.4版里面都 ...

这两个版本都是老的,请下最新的1.3.0版本的BSP吧

使用特权

评论回复
5
fyp5593|  楼主 | 2021-4-1 14:53 | 只看该作者
ArterySW 发表于 2021-4-1 14:22
这两个版本都是老的,请下最新的1.3.0版本的BSP吧

在哪里下?我之前下的库都忘了在哪下的了,官网好像找不到

使用特权

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

本版积分规则

3

主题

10

帖子

0

粉丝