cancel
Showing results for 
Search instead for 
Did you mean: 

I am trying to setup UART on an STM32L072CZTX. I am using interrupt mode and the interrupt seems to be firing due to a pause in main loop execution but nothing inside the interrupt seems to be occurring

JGusl.1
Associate II

I am trying to setup UART on an STM32L072CZTX. In the ioc file I have setup the pins, RX is set to AF4 pullup, and TX is AF4 nopull. The interrupt is set to 0 and enabled. I have redefined the RxCpltCallback in the main and have events occur in there that work when run from main. I can see a pause in main execution (a simple blinking light) but nothing inside the interrupt seems to be happening, flags being set or a different LED blinking.

18 REPLIES 18

Polled UART Rx works?

A simple test, in main loop reading the UART Rx pin input state and setting/clearing LED accordingly, works?

LED blinky alone, works?

JW

JGusl.1
Associate II
	//__HAL_UART_ENABLE_IT(&huart1, UART_IT_RXNE);
 
	//HAL_UART_Receive_IT(&huart1, UART_RX_BUFFER, 20);
 
	while (1)
	{
		HAL_UART_Receive(&huart1, UART_RX_BUFFER, 20, 10000);
		HAL_GPIO_WritePin(GPIOB, GREEN_LED, GPIO_PIN_SET);
		HAL_Delay(100);
		HAL_GPIO_WritePin(GPIOB, GREEN_LED, GPIO_PIN_RESET);

Sending a message doesn't cause the block to exit and blink

JGusl.1
Associate II

Well im not even reading a low pin state at any time so something might be setup wrong with my hardware

Yeah more than likely you don't have the GPIO's set up correctly.

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.
    GPIO_InitStruct.Pin = GPIO_PIN_9;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF4_USART1;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
    GPIO_InitStruct.Pin = GPIO_PIN_10;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_PULLUP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF4_USART1;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

this is how theyre set up

> this is how theyre set up

No. That is just some C code, calling other pieces of C code.

To find out how the GPIO is set up, read out and check/post content of its registers.

But check the HW first using continuity tester and oscilloscope.

JW​

If this init process doesn't tell me then what's the point of using it

See if the attached project works.

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.

Well you have to set it up somehow, but when debugging, you always ​assume the relatively complex way from source code to executed binary may be wrong. The mcu works from the registers and not from C code, that's why the first thing when debugging is to read out registers and check.

But in your case, verify the hardware first.

JW​