關(guān)于ch32x033F8P6usart1重映射到PA10和PA11遇到的問(wèn)題

我根據(jù)stm32的庫(kù)函數(shù)寫(xiě)的代碼

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

??? 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 ;//搶占優(yōu)先級(jí)4
//??? NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4;????? //子優(yōu)先級(jí)4
//??? NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;???????? //IRQ通道使能
//??? NVIC_Init(&NVIC_InitStructure); //根據(jù)指定的參數(shù)初始化VIC寄存器

??? USART_Init(USART1, &USART_InitStructure);
??? //USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//開(kāi)啟串口接受中斷
??? USART_Cmd(USART1, ENABLE);


接下來(lái)是通過(guò)串口一發(fā)消息出來(lái)的代碼,我直接放在main函數(shù)里面的

?? uint16_t Data=0x24;

??? while(1)
??? {

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


接下來(lái)是串口接收中斷

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); //讀取接收到的數(shù)據(jù)

????????????//把數(shù)據(jù)放到隊(duì)列中,隊(duì)列暫時(shí)沒(méi)寫(xiě)
??? }
}


代碼是參考stm32的庫(kù)函數(shù)代碼寫(xiě)的,我實(shí)在不知道哪里有問(wèn)題了,還請(qǐng)賜教,拜托拜托


另外還想請(qǐng)教一下,usb虛擬的串口接收中斷,是不是就是串口2的接收中斷

您好,附件是CH32X033使用PA10、PA11作為串口1引腳的中斷接收輪詢發(fā)送的例程,可以參考一下,注意使用中斷函數(shù),注意要加中斷聲明,如下圖。關(guān)于模擬CDC的例程,我們EVT設(shè)置是配合串口2使用的。后續(xù)若有問(wèn)題,可郵箱(lzs@wch.cn)和我溝通。

icon_rar.gifCH32X033 USART1復(fù)用.zip

image.png


感謝,查看了電路,是因?yàn)閠x引腳串聯(lián)了一個(gè)33r的電阻,把33r的電阻改成了0歐姆的電阻,就能正常發(fā)送消息了


提示下廣大朋友,在重映射時(shí)候,如果單獨(dú)使用tx1即PA10,不要將重映射設(shè)置為GPIO_FullRemap_USART1,這個(gè)不工作,要用GPIO_PartialRemap1_USART1?才行


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

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