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
jpeacock
Associate II
Posted on April 22, 2015 at 19:07

Where do you enable the clock for UART4 with an RCC call?

  Jack Peacock
Posted on April 22, 2015 at 20:16

RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE); // Clock not Reset

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
danpuccio9
Associate II
Posted on April 23, 2015 at 15:51

Thanks for having a look!

I have the UART4 clock enabled at startup.  I should have included the line.  I'll paste it below.  Any other thoughts?

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR|RCC_APB1Periph_CAN1|RCC_APB1Periph_UART4, ENABLE);

danpuccio9
Associate II
Posted on April 23, 2015 at 15:54

Thanks for the suggestion.  The code does enable the clock at startup with the following line:

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR|RCC_APB1Periph_CAN1|RCC_APB1Periph_UART4, ENABLE);

What else could cause this?

danpuccio9
Associate II
Posted on April 24, 2015 at 14:32

So I made a change to poll UART4 and take any byte received and then immediately transmit that byte out the same UART.  That code seems to work OK.

Why won't the interrupt trigger?  What else needs to be enabled?

Posted on April 24, 2015 at 17:04

Dunno, you chose to only show us fragments of code rather than that directly related to your issues.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
danpuccio9
Associate II
Posted on April 24, 2015 at 17:21

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6hG&d=%2Fa%2F0X0000000btS%2FDddtoUK3Wh7PF8JvXO_jEm7CbgJmvDZC9s553ANP36U&asPdf=false
Posted on April 24, 2015 at 17:40

Probably want to service the interrupt source, and not blindly send/receive data in a loop

//interrupt handler, if using C++ (.cpp) make sure name is not mangled.
extern ''C'' void UART4_IRQHandler(void)
{
if (USART_GetITStatus(UART4, USART_IT_RXNE) != RESET) // Confirm source, reading DR clears
USART_SendData(UART4, USART_ReceiveData(UART4)); // Clears RXNE, assumes TXE
LED_SPARE_ON(); //light up an LED (it doesn't get turned off anywhere else in the code)
} 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
danpuccio9
Associate II
Posted on April 24, 2015 at 20:05

Thanks for the help.

The blind receive and send were a test just to confirm that the UART was enabled properly and working, which it seems to be.  It never gets to the ISR.  I added the extern like you had in your post, but it still never gets there.

What else can I test?