ch32v307vct6 用pd8 和pd9 的重映射作为usart3

   如何使用 pd8,pd9 的重映射作为 usart3 使用呢

image.png

  { GPIO_InitTypeDef  GPIO_InitStructure = {0};

    USART_InitTypeDef USART_InitStructure = {0};

    NVIC_InitTypeDef  NVIC_InitStructure = {0};


    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD| RCC_APB2Periph_AFIO, ENABLE);

    GPIO_PinRemapConfig(GPIO_PartialRemap_USART3, ENABLE);



    /* USART3 TX-->D.8  RX-->D.9 */

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

    GPIO_Init(GPIOD, &GPIO_InitStructure);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

            //GPIO_Mode_IN_FLOATING;

    GPIO_Init(GPIOD, &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_Tx | USART_Mode_Rx;


    USART_Init(USART3, &USART_InitStructure);

    //USART_ITConfig(USART3, USART_IT_IDLE, ENABLE);//开启串口空闲中断

    //USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);

    //USART_ClearFlag(USART3, USART_FLAG_TC|USART_FLAG_IDLE);

    USART_Cmd(USART3, ENABLE); //使能串口

}

image.png

你好,你GPIO_PinRemapConfig函数中的参数设置错了,PD8、PD9对应的映射是完全重映射,并非部分重映射。(具体参数可见上图)


好了,谢谢


只有登录才能回复,可以选择微信账号登录