cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 USART RX interrupt notfires, then stuck

csabafrom thehill
Associate II
Posted on August 28, 2017 at 12:02

Hi,

I try to receive characters over USART1 using the StdPeriphLibrary (System Workbench STM32, MCU is SM32F103C8B), but after I get the data the program stuck (transmission works perfectly).

The ISR is:

void USART1_IRQHandler(void)

{

uint16_t rx;

if(USART_GetITStatus(USART1,USART_IT_RXNE)!=RESET) // check RX interrupt

{

rx = USART_ReceiveData(USART1);

led_toggle();

}

}

Whenever data arrives the LED should toggle, but nothing happens, just hangs the code.

USART settings:

void

USART1_Init(

void

)

{

/* USART configuration structure for USART1 */

USART_InitTypeDef usart1_init_struct;

/* Bit configuration structure for GPIOA PIN9 and PIN10 */

GPIO_InitTypeDef gpioa_init_struct;

/* Enalbe clock for USART1, AFIO and GPIOA */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_AFIO |

RCC_APB2Periph_GPIOA, ENABLE);

/* GPIOA PIN9 alternative function Tx */

gpioa_init_struct.GPIO_Pin = GPIO_Pin_9;

gpioa_init_struct.GPIO_Speed = GPIO_Speed_50MHz;

gpioa_init_struct.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_Init(GPIOA, &gpioa_init_struct);

/* GPIOA PIN9 alternative function Rx */

gpioa_init_struct.GPIO_Pin = GPIO_Pin_10;

gpioa_init_struct.GPIO_Speed = GPIO_Speed_50MHz;

gpioa_init_struct.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_Init(GPIOA, &gpioa_init_struct);

/* Enable USART1 */

USART_Cmd(USART1, ENABLE);

/* Baud rate 9600, 8-bit data, One stop bit

* No parity, Do both Rx and Tx, No HW flow control

*/

usart1_init_struct.USART_BaudRate = 9600;

usart1_init_struct.USART_WordLength = USART_WordLength_8b;

usart1_init_struct.USART_StopBits = USART_StopBits_1;

usart1_init_struct.USART_Parity = USART_Parity_No ;

usart1_init_struct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

usart1_init_struct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

/* Configure USART1 */

USART_Init(USART1, &usart1_init_struct);

/* Enable RXNE interrupt */

USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);

/* Enable USART1 global interrupt */

NVIC_EnableIRQ(USART1_IRQn);

}

(the original code is from

http://pandafruits.com/stm32_primer/stm32_primer_uart.php

)

Polling the RX works well.

Is there any suggestions?

2 REPLIES 2
csabafrom thehill
Associate II
Posted on August 28, 2017 at 12:30

Sorry about the title, of course interrupt DOES fire, then stuck...

csabafrom thehill
Associate II
Posted on August 31, 2017 at 15:36

After I tried to enable Timer which also did not work I thought the code may be right, the problem was with the SystemWorkbench. Then I found that the AC6 makes a default startup file with only some interrupt. Downloaded CubeMX, made a very simple projec, copied the startup file to the project, and voila!

Everything works!