AnsweredAssumed Answered

STM32F0 RX interrupt not working

Question asked by booysen.tracy on Oct 6, 2015
Latest reply on Oct 6, 2015 by waclawek.jan
I have an STM32F0 which is receiving and transmitting serial data. When I send the data another board responds. If I poll RXNE looking for the data and store it in an array like this everything works:

          //while ((USART1->ISR & USART_ISR_RXNE) == 0);
          //receiveArray[0] = USART1->RDR;
          //while ((USART1->ISR & USART_ISR_RXNE) == 0);
          //receiveArray[1] = USART1->RDR;
          //while ((USART1->ISR & USART_ISR_RXNE) == 0);
          //receiveArray[2] = USART1->RDR;
          //while ((USART1->ISR & USART_ISR_RXNE) == 0);
          //receiveArray[3] = USART1->RDR;

However when I use the interrupt the first byte is received and then the interrupt continues to interrupt even after data is no longer being transmitted and the line is high. What makes it even stranger is that the RXNE bit is not even being set!

The USART setup is below and then my interrupt function.

void init_usart() {
     // clock to USART1
     RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
     // clock to GPIOA
     RCC->AHBENR |= RCC_AHBENR_GPIOAEN;
     // PA9 and PA10 to AF
     GPIOA->MODER |= GPIO_MODER_MODER9_1;
     GPIOA->MODER |= GPIO_MODER_MODER10_1;
     // remap to correct AF
     GPIOA->AFR[1] |= (1 << (1*4)); // remap pin 9 to AF1
     GPIOA->AFR[1] |= (1 << (2*4)); // remap pin 10 to AF1


     SystemCoreClockUpdate();
     USART1->BRR = SystemCoreClock/9600; //0x1388;


     // enable with UE in CR1
     //USART1->CR2 |= USART_CR2_SWAP;
     USART1->CR1 |= USART_CR1_UE;
     USART1->CR1 |= USART_CR1_RXNEIE;
     USART1->CR1 |= USART_CR1_RE;
     USART1->CR1 |= USART_CR1_TE;
}

void init_NVIC() {
     NVIC_EnableIRQ(USART1_IRQn);
}

void USART1_IRQHandler(void){
     
     if ((USART1->ISR & USART_ISR_RXNE) == USART_ISR_RXNE){
          receiveArray[(packetReceivedIndex)++] = (uint8_t)(USART1->RDR);
     }

data =(uint8_t)(USART1->RDR); //dummy read just in case
}

Outcomes