cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0 RX interrupt not working

tracy
Associate II
Posted on October 06, 2015 at 08:52

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

}

4 REPLIES 4
Posted on October 06, 2015 at 10:01

And what is the content of  USART1_ISR? Note, that overrun error is enabled through CR1.RXNEIE too.

JW

tracy
Associate II
Posted on October 06, 2015 at 15:25

I did include the interrupt for USART1. I tried to check the overflow and the framing error inside the interrupt like this: 

// if (USART1->ISR & USART_ISR_ORE == USART_ISR_ORE){

// trace_puts(''overflow error'');

// }

but I never saw the overflow.v Is there something I am missing here?

Thanks

Tracy

tracy
Associate II
Posted on October 06, 2015 at 15:49

Apologies there was a missing bracket - turns out I am getting overrun errors. But on the scope the data look perfect 1 stop bit high 1 start bit low. Why would this be causing an overrun. I am also doing nothing in the interrupt and nothing in the main code?

Posted on October 06, 2015 at 15:59

> I did include the interrupt for USART1. I tried to check the overflow and the framing error inside the interrupt

That seems OK. I don't see any other problem. But again, try to get somehow the value of USART_ISR register. That's what I'd do. I'd also double check (read out) the value of all control registers. In fact, I'd use a debugger to place a breakpoint inside the ISR and observe all the registers (bearing in mind that reading the data register clears the receive flag etc.)

JW