欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2472|回復: 2
收起左側

用串口模擬仿真 STM32一直沒有IDLE中斷,請高手幫忙看看!

[復制鏈接]
ID:713367 發表于 2020-5-7 22:39 | 顯示全部樓層 |閱讀模式
用串口模擬仿真,通過串口接收到一幀數據后,一直沒有IDLE中斷。折騰好長時間也沒發現問題在哪。

u8 rxbuffer[100]={0x00};
u8 txbuffer[100]={0x00};
u8 flag=0;
static int rx_count=0;

void usart_gpio_init(void)
{
                RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO , ENABLE);
                GPIO_InitTypeDef GPIO_InitStructure;
                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_Speed = GPIO_Speed_50MHz;
                GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
                GPIO_Init(GPIOA, &GPIO_InitStructure);
                GPIO_Init(GPIOA, &GPIO_InitStructure);
}

void usart_init(void)
{
                RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 , ENABLE);
                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_Cmd(USART1, ENABLE);
        
                USART_ITConfig(USART1,USART_IT_RXNE,ENABLE); //使能接收中斷
                USART_ITConfig(USART1,USART_IT_IDLE ,ENABLE); //使能空閑總線中斷
                USART_ClearFlag(USART1,USART_FLAG_TC); //清除發送完成標志位
}

void usart_nvic_init(void)
{
                NVIC_InitTypeDef NVIC_InitStructure;
                NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
                NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn ;
                NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
                NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
                NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
                NVIC_Init(&NVIC_InitStructure);
}

void usart_config(void)
{
                usart_gpio_init();
                usart_init();
                usart_nvic_init();
}


//串口接收中斷
void USART1_IRQHandler(void)                 //串口1中斷服務程序
{                        
                if(USART_GetFlagStatus(USART1, USART_FLAG_RXNE )!=RESET)//接收到一字節數據
                {        
                                rxbuffer[rx_count++]=USART_ReceiveData(USART1);
                                USART_ClearFlag(USART1,USART_IT_RXNE);
                                if(USART_GetFlagStatus(USART1, USART_FLAG_IDLE)!= RESET)  //接收到一幀數據
                                {                                
                                                USART1->SR;
                                                USART1->DR;
                                                flag=1;
                                                USART_ClearFlag(USART1, USART_FLAG_IDLE);
                                                usart1_send_onebyte(0x26);
                                }
                                //usart1_send_onebyte(0x27);
                                
                }
}

回復

使用道具 舉報

ID:328075 發表于 2022-4-27 11:00 | 顯示全部樓層
中斷程序寫的有問題
回復

使用道具 舉報

ID:282861 發表于 2022-5-7 14:38 | 顯示全部樓層
中斷程序應該用USART_GetITStatus(),但是我還是沒有調成功,正在研究。
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表