CH32V103C8T6芯片 不能实现usart接收中断

参照芯片提供的案例,自己的代码如下:

#include "debug.h"
#include "stepper.h"
#include "recBleSignal.h"

u16 uartData;
void USART1_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));

void USARTx_CFG(void)
{
??? GPIO_InitTypeDef? GPIO_InitStructure = {0};
??? USART_InitTypeDef USART_InitStructure = {0};
??? NVIC_InitTypeDef? NVIC_InitStructure = {0};

??? RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1, ENABLE);

??? /* USART1 TX-->A.9?? RX-->A.10 */
??? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
??? 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_10;
??? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;??? //案例中用的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(USART1, &USART_InitStructure);
??? USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);

??? NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
??? NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
??? NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
??? NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
??? NVIC_Init(&NVIC_InitStructure);

??? USART_Cmd(USART1, ENABLE);
}

int main(void)
{
??? SystemInit();????????????????????????????????????? //调用内部时钟倍频 一定要初始化时钟
??? NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);??? //中断优先级配置
??? Delay_Init();????????????????????????????????????? //使用延时? 必须得初始化延时函数


??? LED_init();?? //初始化LED灯
??? USARTx_CFG();
??? while(1){}

}


void USART1_IRQHandler(void)
{
??? if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET){
??????? if(USART_ReceiveData(USART1)){
??????????? LED_Ctrl(LED1, ON);? //接收到数据后亮红灯
??????? }
??????? USART_ClearITPendingBit(USART1, USART_IT_RXNE);
??? }
}



以上是我写的代码,发现串口接收无论如何都实现不了,不用中断的话? 串口接收没有问题,帮忙看下问题出在哪

您好,程序配置有点问题,把USART2改成USART1试一下。

image.png


奇怪了? 我改完之后编译下载仍然不行,完了我把MR关了 重新打开编译下载就可以了


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