CH32V103C8T6芯片 不能實(shí)現(xiàn)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();????????????????????????????????????? //調(diào)用內(nèi)部時(shí)鐘倍頻 一定要初始化時(shí)鐘
??? NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);??? //中斷優(yōu)先級配置
??? Delay_Init();????????????????????????????????????? //使用延時(shí)? 必須得初始化延時(shí)函數(shù)


??? 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);? //接收到數(shù)據(jù)后亮紅燈
??????? }
??????? USART_ClearITPendingBit(USART1, USART_IT_RXNE);
??? }
}



以上是我寫的代碼,發(fā)現(xiàn)串口接收無論如何都實(shí)現(xiàn)不了,不用中斷的話? 串口接收沒有問題,幫忙看下問題出在哪

您好,程序配置有點(diǎn)問題,把USART2改成USART1試一下。

image.png


奇怪了? 我改完之后編譯下載仍然不行,完了我把MR關(guān)了 重新打開編譯下載就可以了


只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频