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

標題: stm32f103c8t6串口能發不能收,進不去中斷,請求大神幫助 [打印本頁]

作者: mrjhl    時間: 2020-4-27 13:37
標題: stm32f103c8t6串口能發不能收,進不去中斷,請求大神幫助
void uart_init(u32 bound){

  GPIO_InitTypeDef GPIO_InitStrue;
        USART_InitTypeDef USART_InitStrue;
        NVIC_InitTypeDef NVIC_InitStrue;
        
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA ,ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
        
        GPIO_InitStrue.GPIO_Mode=GPIO_Mode_AF_PP;
        GPIO_InitStrue.GPIO_Pin=GPIO_Pin_2;
        GPIO_InitStrue.GPIO_Speed=GPIO_Speed_10MHz;
  GPIO_Init(GPIOA,&GPIO_InitStrue);//?
        
        GPIO_InitStrue.GPIO_Mode=GPIO_Mode_IN_FLOATING;
//        GPIO_InitStrue.GPIO_Mode=GPIO_Mode_IPU;
        GPIO_InitStrue.GPIO_Pin=GPIO_Pin_3;
        GPIO_InitStrue.GPIO_Speed=GPIO_Speed_10MHz;
  GPIO_Init(GPIOA,&GPIO_InitStrue);//?
        
        USART_InitStrue.USART_BaudRate=bound;
        USART_InitStrue.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
        USART_InitStrue.USART_Mode=USART_Mode_Tx|USART_Mode_Rx;
        USART_InitStrue.USART_Parity=USART_Parity_No;
        USART_InitStrue.USART_StopBits=USART_StopBits_1;
        USART_InitStrue.USART_WordLength=USART_WordLength_8b;
        
        USART_Init(USART2,&USART_InitStrue);//USART2 init
        
        USART_Cmd(USART2,ENABLE);//USART2  enable
        
        USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
        
        NVIC_InitStrue.NVIC_IRQChannel=USART2_IRQn;
        NVIC_InitStrue.NVIC_IRQChannelCmd=ENABLE;
        NVIC_InitStrue.NVIC_IRQChannelPreemptionPriority=1;
        NVIC_InitStrue.NVIC_IRQChannelSubPriority=1;
        NVIC_Init(&NVIC_InitStrue);
        
        
}

void USART2_IRQHandler(void)                        //′®¿ú2ÖD¶Ï·tÎñ3ìDò
        {
        u8 Res;

        if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)  //
                {
                Res =USART_ReceiveData(USART2);        //
                USART_SendData(USART2,Res);
                                 
     }

}
int main(void)
{               
         u16 t;       unsigned char i = 0;
        u16 len;        
        u16 times=0;
        delay_init();                     //  
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //
        uart_init(9600);         //
         LED_Init();                             

         while(1)
        {
      delay_ms(1000);
      USART_SendData(USART2,0x36);                        
        
        }         
}

作者: 不要笑    時間: 2021-9-26 15:21
中斷函數結尾加上這一條就可以了 USART_ClearITPendingBit(USART2,USART_IT_RXNE);  //清空接收中斷標志位
作者: Roter    時間: 2021-9-26 16:57
時鐘開啟了嗎?中斷使能了嗎?




歡迎光臨 (http://m.raoushi.com/bbs/) Powered by Discuz! X3.1