cancel
Showing results for 
Search instead for 
Did you mean: 

UART receive interrupt

danpuccio9
Associate II
Posted on April 22, 2015 at 19:02

I have a board using an STM32F105.  There is a GPS connected to UART4.  I've been trying to get the RXNE interrupt working for a couple of days now, but I must be missing something.

The UART seems to be enabled, as I can send data.  It doesn't get to the receive interrupt, though.  I wrote some simple code to poll the UART and to take any data received and then transmit that data.  No matter what data is present on the bus, the data sent is 0x00.  Because of this, I think that I have something set incorrectly in my UART configuration.  Can someone please have a look at the setup and give me a nudge in the right direction?

Thanks!

  USART_InitTypeDef  USART_InitStructure;

  GPIO_InitTypeDef GPIO_InitStructure;

  NVIC_InitTypeDef NVIC_InitStructure;

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

  //RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4, ENABLE);

 

 

  /* Configure USART pins */

  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_10;    //TX

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

  GPIO_Init(GPIOC, &GPIO_InitStructure);

 

  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_11;    //RX

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

  GPIO_Init(GPIOC, &GPIO_InitStructure);

  /* UART configuration */

  USART_DeInit(UART4);

  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_Mode = USART_Mode_Rx | USART_Mode_Tx;

  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

  USART_Init(UART4, &USART_InitStructure);

  //select NVIC channel to configure

  NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 13;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

  NVIC_SetPriority(UART4_IRQn, NVIC_EncodePriority(4,1,0));

  NVIC_EnableIRQ(UART4_IRQn);

  USART_ITConfig(UART4, USART_IT_ERR, ENABLE);

  USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);

  USART_Cmd(UART4, ENABLE);

#stm32 #usart #receive
11 REPLIES 11
Morgan.Doug
Associate II
Posted on April 24, 2015 at 20:38

I don't see a call to configure the alternate function numbers for the USART (or anything else).   The HAL call would be to GPIO_PinAFConfig.

Doug

Posted on April 24, 2015 at 20:43

What else can I test?

Well does the RXNE bit ever get set in the status register? You won't get an interrupt unless it actually receives something.

How is this wired externally? The CMOS outputs are not compatible with RS232 levels.

Can you directly loop back the TX and RX pins? Does that work?

Do you have a scope? Can you wait on TXE and send a continuous stream of 0x55 characters?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..