uart7 PA6 PA7 串口数据发出?

代码没多少,就是配置一下直接发数据

使用PA6 PA7 发送串口数据

int main(void)

{

    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);

    Delay_Init();


   // USART_interIni();

    GPIO_InitTypeDef  GPIO_InitStructure = {0};

    USART_InitTypeDef USART_InitStructure = {0};

    NVIC_InitTypeDef  NVIC_InitStructure = {0};


    RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART7 , ENABLE);

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_AFIO, ENABLE);

    //RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE);

    GPIO_PinRemapConfig(GPIO_FullRemap_USART7,ENABLE);

    //GPIO_PinRemapConfig(GPIO_PartialRemap_USART7,ENABLE);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

    GPIO_Init(GPIOA, &GPIO_InitStructure);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

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

    USART_Init(UART7, &USART_InitStructure);

    USART_ITConfig(UART7, USART_IT_RXNE, DISABLE);

    NVIC_InitStructure.NVIC_IRQChannel = UART7_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

    USART_Cmd(UART7, ENABLE);

    //u8 TxBuffer2[] = "#Buffer2 Send from USART3 to USART2 using HalfDuplex Mode!";

    while(1)

    {

        Delay_Ms(1000);

        for(int i=0;i<20;i++)

        USART_SendData(UART7, TxBuffer2[i]);

    }

}


芯片使用CH32V307VCT6


你好,我看你这边使用的是GPIO_FullRemap_USART7,此为完全重映射,对应引脚为PE12-PE13,如果想映射为PA6-PA7,需开启部分重映射。具体可看手册。另外需要注意的是后面  _1代表的就是部分映射。 

image.png

image.png

image.png


可以的,谢谢。


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