关于ch32x033F8P6usart1重映射到PA10和PA11遇到的问题

我根据stm32的库函数写的代码

下面是串口一的初始化代码

??? RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO, ENABLE);
??? GPIO_InitTypeDef? GPIO_InitStructure={0};
??? USART_InitTypeDef USART_InitStructure={0};
??? //NVIC_InitTypeDef NVIC_InitStructure;

??? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
??? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
??? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
??? GPIO_Init(GPIOA, &GPIO_InitStructure);
?? GPIO_PinRemapConfig(GPIO_PartialRemap1_USART1, ENABLE);

??? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
??? 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_Rx | USART_Mode_Tx;

//??? NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
//??? NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=4 ;//抢占优先级4
//??? NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4;????? //子优先级4
//??? NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;???????? //IRQ通道使能
//??? NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器

??? USART_Init(USART1, &USART_InitStructure);
??? //USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//开启串口接受中断
??? USART_Cmd(USART1, ENABLE);


接下来是通过串口一发消息出来的代码,我直接放在main函数里面的

?? uint16_t Data=0x24;

??? while(1)
??? {

??????? USART_SendData(USART1, Data);
??????? Delay_Ms(500);
??? }


接下来是串口接收中断

void USART1_IRQHandler(void)
{
??? uint8_t rec = 0;

??? if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
??? {
??????????? USART_ClearITPendingBit(USART1, USART_IT_RXNE);
??????????? rec = USART_ReceiveData(USART1); //读取接收到的数据

????????????//把数据放到队列中,队列暂时没写
??? }
}


代码是参考stm32的库函数代码写的,我实在不知道哪里有问题了,还请赐教,拜托拜托


另外还想请教一下,usb虚拟的串口接收中断,是不是就是串口2的接收中断

您好,附件是CH32X033使用PA10、PA11作为串口1引脚的中断接收轮询发送的例程,可以参考一下,注意使用中断函数,注意要加中断声明,如下图。关于模拟CDC的例程,我们EVT设置是配合串口2使用的。后续若有问题,可邮箱(lzs@wch.cn)和我沟通。

icon_rar.gifCH32X033 USART1复用.zip

image.png


感谢,查看了电路,是因为tx引脚串联了一个33r的电阻,把33r的电阻改成了0欧姆的电阻,就能正常发送消息了


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