標(biāo)題: STM32串口通訊程序,無法進(jìn)入接收中斷 [打印本頁]

作者: honeychen    時(shí)間: 2021-11-12 09:33
標(biāo)題: STM32串口通訊程序,無法進(jìn)入接收中斷
我感覺我的配置部分是沒有問題的,就是不知道哪里出了問題
void RS485_Configuration(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
        USART_InitTypeDef USART_InitStructure;
        
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
        
        //RS485接收發(fā)送使能,不需接線,只需要電平信號(hào)
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;        
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_Init(GPIOB, &GPIO_InitStructure);
        
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;        //TX
        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_3;        //RX
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
        GPIO_Init(GPIOA, &GPIO_InitStructure);        


        USART_InitStructure.USART_BaudRate = 9600;
        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(USART2, &USART_InitStructure);
        
        USART_ITConfig(USART2, USART_IT_RXNE,ENABLE);        

        USART_Cmd(USART2, ENABLE);
        
        //默認(rèn)設(shè)置為接收模式,低電平
        RS485_Receive;
}

void USART2_NVIC_Configuration(void)
{
        NVIC_InitTypeDef NVIC_InitStructure;
        NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);        
}

跪求跪求,救救孩子吧

作者: bitatabi    時(shí)間: 2021-11-13 22:12
其他中斷能不能進(jìn)?




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