2015-04-22 10:02 AM
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 #receive2015-04-22 10:07 AM
Where do you enable the clock for UART4 with an RCC call?
Jack Peacock2015-04-22 11:16 AM
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE); // Clock not Reset
2015-04-23 06:51 AM
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);2015-04-23 06:54 AM
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?2015-04-24 05:32 AM
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?2015-04-24 08:04 AM
Dunno, you chose to only show us fragments of code rather than that directly related to your issues.
2015-04-24 08:21 AM
2015-04-24 08:40 AM
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)
}
2015-04-24 11:05 AM
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?