78730460 发表于 2021-6-19 12:54

串口1复用测试不通过,原厂技术支持请回复。-done

本帖最后由 muyichuan2012 于 2021-6-23 09:42 编辑

芯片型号 AT32F421C8T6,串口1默认在PA9和PA10,布板原因,把端口改到了PB6和PB7。现在调试不通过,代码如下:
#define USART1_TX_PORT       GPIOB
#define USART1_TX_PIN      GPIO_Pins_6
#define USART1_TX_SOURCE   GPIO_PinsSource6
#define USART1_TX_AF         GPIO_AF_1

#define USART1_RX_PORT       GPIOB
#define USART1_RX_PIN      GPIO_Pins_7
#define USART1_RX_SOURCE   GPIO_PinsSource7
#define USART1_RX_AF         GPIO_AF_1

#define USART1_GPIO_RCC      RCC_AHBPERIPH_GPIOB


static void bsp_InitHardUART(void)
{
    GPIO_InitType GPIO_InitStructure;
    USART_InitType USART_InitStructure;

#if USART1_EN
    RCC_AHBPeriphClockCmd(USART1_GPIO_RCC, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_USART1, ENABLE);

    GPIO_StructInit(&GPIO_InitStructure);
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_MaxSpeed = GPIO_MaxSpeed_50MHz;

    GPIO_InitStructure.GPIO_Pins = USART1_TX_PIN;
    GPIO_InitStructure.GPIO_OutType = GPIO_OutType_PP;
    GPIO_Init(USART1_TX_PORT, &GPIO_InitStructure);

    GPIO_InitStructure.GPIO_Pins = USART1_RX_PIN;
    GPIO_InitStructure.GPIO_Pull = GPIO_Pull_PU;
    GPIO_Init(USART1_RX_PORT, &GPIO_InitStructure);

    GPIO_PinAFConfig(USART1_TX_PORT, USART1_TX_SOURCE, USART1_TX_AF);
    GPIO_PinAFConfig(USART1_RX_PORT, USART1_RX_SOURCE, USART1_RX_AF);

    USART_InitStructure.USART_BaudRate = USART1_BAUD;                              
    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(USART1, &USART_InitStructure);

    USART_INTConfig(USART1, USART_INT_RDNE, ENABLE);

    USART_Cmd(USART1, ENABLE);
#endif

}
不知道代码哪里有问题,请大家帮助看看!

hoop 发表于 2021-6-19 14:35

你的AF配置错误,请参考RM

78730460 发表于 2021-6-22 21:10

hoop 发表于 2021-6-19 14:35
你的AF配置错误,请参考RM

#define USART1_TX_PORT       GPIOB
#define USART1_TX_PIN      GPIO_Pins_6
#define USART1_TX_SOURCE   GPIO_PinsSource6
#define USART1_TX_AF         GPIO_AF_0

#define USART1_RX_PORT       GPIOB
#define USART1_RX_PIN      GPIO_Pins_7
#define USART1_RX_SOURCE   GPIO_PinsSource7
#define USART1_RX_AF         GPIO_AF_0

改成这样测试依然收不到串口数据

78730460 发表于 2021-6-22 21:19

hoop 发表于 2021-6-19 14:35
你的AF配置错误,请参考RM

#define USART1_TX_PORT       GPIOB
#define USART1_TX_PIN      GPIO_Pins_6
#define USART1_TX_SOURCE   GPIO_PinsSource6
#define USART1_TX_AF         GPIO_AF_0

#define USART1_RX_PORT       GPIOB
#define USART1_RX_PIN      GPIO_Pins_7
#define USART1_RX_SOURCE   GPIO_PinsSource7
#define USART1_RX_AF         GPIO_AF_0

skyred 发表于 2021-7-3 10:47

这种情况,检查引脚分配和初始化部分
页: [1]
查看完整版本: 串口1复用测试不通过,原厂技术支持请回复。-done