各位老師好,請(qǐng)教:CH32V307VCT6 串口中斷只能進(jìn)入1次問(wèn)題?
環(huán)境:沁恒官方申請(qǐng)的307開(kāi)發(fā)板+MRS。為驗(yàn)證和實(shí)驗(yàn),用mrs生成工程后,即對(duì)串口初始,沒(méi)有多余的其他應(yīng)用了。
現(xiàn)象:串口1,中斷方式,板子每次復(fù)位后能夠接收1個(gè)字節(jié),之后再收不到了。只能再?gòu)?fù)位,后只能收到1個(gè)字節(jié)。
?? 例:
?????????我測(cè)試應(yīng)用里,串口助手 發(fā),0xA1 ,點(diǎn)亮了PA0 掛載的LED;再發(fā)0xA2 無(wú)反應(yīng)。感覺(jué)觸發(fā)串口中斷后就掛在哪個(gè)地方死循環(huán)出不來(lái)一樣。
? 板子復(fù)位啟動(dòng)時(shí)能收到printf發(fā)來(lái)的字符,說(shuō)明串口和硬件是無(wú)問(wèn)題的。
(??????? 后用CH32V203C8T6 也用一樣的方法測(cè)試,結(jié)果一樣,肯定是我那個(gè)地方用的不對(duì),肯定是我那個(gè)地方用的不對(duì),
????困擾2天了,遲遲無(wú)法移植到業(yè)務(wù)項(xiàng)目中,
??? 懇請(qǐng)各位老大指導(dǎo)指導(dǎo) ??!? 感謝??!
? )
#include "debug.h"
char RxPacket[64]; //接收緩沖區(qū)
char TxPacket[64]; //發(fā)送緩沖區(qū)
uint8_t Serial_RxFlag; //接收完畢標(biāo)志位
uint8_t pRxPacket = 0;
//===========================================
// 串口初始化
// 使用COM1 口:PA9、10
//===========================================
void Uart_Init(void)
{
??? RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
??? RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
??? //GPIO端口設(shè)置
??? GPIO_InitTypeDef GPIO_InitStructure;
??????? //普通IO設(shè)置
??????? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
??????? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 |GPIO_Pin_1;
??????? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
??????? GPIO_Init(GPIOA, &GPIO_InitStructure);
??? //USART1_TX?? PA.9
??? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
??? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;// USART1_Tx(PA9).
??? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
??? GPIO_Init(GPIOA, &GPIO_InitStructure);
??? //USART1_RX?? PA.10
??? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
??? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
??? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
??? GPIO_Init(GPIOA, &GPIO_InitStructure);
??? //Usart1 NVIC 配置
??? NVIC_InitTypeDef NVIC_InitStructure;
??? NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
??? NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//IRQ通道使能
??? NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;//搶占優(yōu)先級(jí)
??? NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;//子優(yōu)先級(jí)
??? NVIC_Init(&NVIC_InitStructure);
??? //USART 初始化設(shè)置
??? USART_InitTypeDef USART_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);//開(kāi)啟中斷
??? USART_Cmd(USART1, ENABLE);//使能串口1
}
//===========================================
// 串口1 中斷
//===========================================
void USART1_IRQHandler(void)
{
??? uint8_t RxData;
??????? if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET )
??????? {
??????????? RxData = USART_ReceiveData(USART1); //獲取數(shù)據(jù)
??????????? if(RxData==0xA1) GPIO_ResetBits(GPIOA, GPIO_Pin_0);
??????????? if(RxData==0xA2) GPIO_SetBits(GPIOA, GPIO_Pin_0);
??????? }
}
//==========================================================
// 主函數(shù)
//==========================================================
int main(void)
{
??? NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
?? ?SystemCoreClockUpdate();
?? ?Delay_Init();
?? ?USART_Printf_Init(115200);
?? ?printf("SystemClk:%d\r\n",SystemCoreClock);
?? ?Uart_Init();? //串口初始化
?? ?GPIO_SetBits(GPIOA, GPIO_Pin_0 | GPIO_Pin_1);
?? ?while(1)
??? {
????}
}