如題:現(xiàn)在是 接收中斷 能_且僅能_進(jìn)入一次(PC單次發(fā)一個字節(jié))。相關(guān)代碼已經(jīng)參考過例程。相關(guān)問題也已經(jīng)度娘。
相關(guān)代碼如下:
void?USART_GPIO_Init() { ??GPIO_InitTypeDef?GPIO_InitStructure; ??NVIC_InitTypeDef??NVIC_InitStructure; ??RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA,?ENABLE); ??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_IN_FLOATING; ??GPIO_Init(GPIOA,?&GPIO_InitStructure); ??USART_ITConfig(USART1,?USART_IT_RXNE,?ENABLE); ??NVIC_InitStructure.NVIC_IRQChannel?=?USART1_IRQn; ??NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1; ??NVIC_InitStructure.NVIC_IRQChannelSubPriority?=?0; ??NVIC_InitStructure.NVIC_IRQChannelCmd?=?ENABLE; ??NVIC_Init(&NVIC_InitStructure); } void?USART_Setup(uint32_t?baudrate) { ??USART_InitTypeDef?USART_InitStructure; ??USART_InitStructure.USART_BaudRate?=?baudrate; ??USART_InitStructure.USART_WordLength?=?USART_WordLength_8b; ??USART_InitStructure.USART_StopBits?=?USART_StopBits_2; ??USART_InitStructure.USART_Parity?=?USART_Parity_No; ??USART_InitStructure.USART_HardwareFlowControl?=?USART_HardwareFlowControl_None; ??USART_InitStructure.USART_Mode?=?USART_Mode_Rx?|?USART_Mode_Tx; ??USART_Init(USART1,?&USART_InitStructure); ??USART_Cmd(USART1,?ENABLE); } /******************************************************************************* *?Function?Name??:?USART1_IRQHandler *?Description????:?This?function?handles?USART1?global?interrupt?request. *?Input??????????:?None *?Return?????????:?None *******************************************************************************/ void?USART1_IRQHandler(void) { ??if(USART_GetITStatus(USART1,?USART_IT_RXNE)?!=?RESET) ??{ ??????u8?t?=?USART_ReceiveData(USART1)&0x7F; ????????if(t?==?0x11)send_st?=?1; ????????else?if(t?==?0x13)send_st?=?0; ??} int?main() { UINT8?s,?i; ????NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); ????Delay_Init(); ????USART_GPIO_Init(); ????USART_Setup(19200); printf("SystemClk:%d\r\n",SystemCoreClock);
熱門產(chǎn)品 :
CH397: 高集成度、低功耗USB網(wǎng)卡芯片