[AT32F403/403A] UART5初始化后发不出数据,请帮忙看看

[复制链接]
1449|3
 楼主| dopod577w 发表于 2022-5-27 19:55 | 显示全部楼层 |阅读模式
用的是403A的评估板,串口选的是UART5,管脚PB8,PB9,串口初始化代码如下
  1. void usart_configuration(void)
  2. {
  3.         gpio_init_type gpio_init_struct;

  4.         /* enable the usart5 and gpio clock */
  5.         crm_periph_clock_enable(CRM_UART5_PERIPH_CLOCK, TRUE);
  6.         crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);

  7.         gpio_default_para_init(&gpio_init_struct);

  8.         /* configure the usart5 tx pin */
  9.         gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
  10.         gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
  11.         gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
  12.         gpio_init_struct.gpio_pins = GPIO_PINS_9;
  13.         gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
  14.         gpio_init(GPIOB, &gpio_init_struct);

  15.         /* configure the usart5 rx pin */
  16.         gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
  17.         gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
  18.         gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
  19.         gpio_init_struct.gpio_pins = GPIO_PINS_8;
  20.         gpio_init_struct.gpio_pull = GPIO_PULL_UP;
  21.         gpio_init(GPIOB, &gpio_init_struct);

  22.         /* config usart nvic interrupt */
  23.         nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
  24.         nvic_irq_enable(UART5_IRQn, 0, 0);

  25.         /* configure usart5 param */
  26.         usart_init(UART5, 115200, USART_DATA_8BITS, USART_STOP_1_BIT);
  27.         usart_transmitter_enable(UART5, TRUE);
  28.         usart_receiver_enable(UART5, TRUE);
  29.         usart_interrupt_enable(UART5, USART_IDLE_INT, TRUE);
  30.         usart_enable(UART5, TRUE);
  31. }
主程序中循环发送一个字节:
  1. for(;;)
  2.         {
  3.                 while(usart_flag_get(UART5, USART_TDBE_FLAG) == RESET);
  4.                 usart_data_transmit(UART5, 0x55);
  5.                 delay_ms(1);
  6.         }
用示波器测管脚PB9 (TXD5),没有高低变化

请问怎么回事?
骑着蜗牛狂奔O 发表于 2022-5-27 20:09 | 显示全部楼层
要开AFIO时钟,并使能串口引脚的重映射
 楼主| dopod577w 发表于 2022-5-27 21:40 | 显示全部楼层
多谢,可以出信号了
下面要调试中断了,感觉挺麻烦的,ST的CubeMX用惯了,懒了
话说当年 发表于 2022-6-1 21:15 | 显示全部楼层
本帖最后由 话说当年 于 2022-6-1 21:16 编辑

你可用串口5的TX是PC12;RX是PD2.我已经把8个串口都试过了, 没啥问题。你重映射出现问题了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

12

主题

26

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部