STM32G4 Irq Handler block main function

39 Views Asked by At

I am trying to write a USART interrupt to read input from a serial terminal and pass that value to another function. While the interrupt works, it is for some reason blocking the program as if I were to go into debug mode, the program would keep looping at the USART2_IRQHandler().

void USART2_Init(void){
    RCC->APB1ENR1 |= RCC_APB1ENR1_USART2EN;
    RCC->AHB2ENR  |= RCC_AHB2ENR_GPIOAEN;
    
    
    GPIOA->MODER &= ~(GPIO_MODER_MODE2|GPIO_MODER_MODE3|GPIO_MODER_MODE5);
    GPIOA->MODER |= (0x02 << GPIO_MODER_MODE2_Pos | 0x02 << GPIO_MODER_MODE3_Pos | 0x01 << GPIO_MODER_MODE5_Pos);
    GPIOA->AFR[0] |= (0x07<<GPIO_AFRL_AFSEL2_Pos | 0x07 <<GPIO_AFRL_AFSEL3_Pos);
    GPIOA->BSRR |= GPIO_BSRR_BS5;
    
    USART2->CR1 |= USART_CR1_TXEIE;
    USART2->CR1 |= USART_CR1_RXNEIE;
    USART2->BRR  = (uint16_t)(16000000/9600);
    
    USART2->CR1 |= USART_CR1_TE;
    USART2->CR1 |= USART_CR1_RE;
    USART2->CR1 |= USART_CR1_UE;
    
    NVIC->IP[USART2_IRQn] |= (0X01<<4);
    NVIC->ISER[38>>5] |= (1<<(38%32));
}

void USART2_IRQHandler(void){
    if (USART2->ISR & USART_ISR_RXNE){
        rx = USART2->RDR;
        rx_counter++;
            
        if (rx_counter == 1){
            rx_buffer |= (rx & 0x0F) << 8;
            GPIOA->BRR |= GPIO_BRR_BR5;
        }
        else if (rx_counter == 2){
            rx_buffer |= rx & 0xFF;
            
            #ifdef AD5593R
            AD5593R_WriteDAC(AD5593R_CH1,rx_buffer);
            #endif
            
            #ifdef MCP4728
            MCP4728_GeneralCall(MCP4728_RESET);
            MCP4728_GeneralCall(MCP4728_WAKEUP);
            MCP4728_SingleTransmit(CHANNEL_A,rx_buffer);
            #endif
            
            rx_buffer = 0;
            rx_counter = 0;
            GPIOA->BSRR |= GPIO_BSRR_BS5;
        }
        while((USART2->ISR & USART_ISR_RXNE)){}
    }
    
}
0

There are 0 best solutions below