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
Karl Yamashita
Lead III

You don't say what mode you're using to receive data. Are you polling, interrupt or DMA?

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.
JGusl.1
Associate II

"I am using interrupt mode"

Karl Yamashita
Lead III

post your code for RxCpltCallback().

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.
JGusl.1
Associate II
volatile uint8_t  flag = 0;
 
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
	flag = 1;
	//HAL_UART_Transmit(&huart1, UART_RX_BUFFER, sizeof(UART_RX_BUFFER), 100);
	//HAL_Delay(500);
	HAL_UART_Receive_IT(&huart1, UART_RX_BUFFER, 20); //restart the interrupt reception
}
main (void)
{
HAL_UART_Receive_IT(&huart1, UART_RX_BUFFER, 20);
       while (1)
	{
		if (flag == 1)
		{
 
			HAL_GPIO_WritePin(GPIOB, RED_LED, GPIO_PIN_SET);
			HAL_Delay(250);
			HAL_GPIO_WritePin(GPIOB, RED_LED, GPIO_PIN_RESET);
			HAL_Delay(250);
 
			flag = 0;
		}
		else
		{
 
			HAL_GPIO_WritePin(GPIOB, GREEN_LED, GPIO_PIN_SET);
			HAL_Delay(250);
			HAL_GPIO_WritePin(GPIOB, GREEN_LED, GPIO_PIN_RESET);
			HAL_Delay(250);
 
		}
}

JGusl.1
Associate II

That main loop never changes to the RED_LED loop

Karl Yamashita
Lead III

what kind of UART data are you expecting?

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.
JGusl.1
Associate II

Just strings. I'm trying to inject them temporarily using a serial monitor. Im sending strings longer than 20 bytes

Karl Yamashita
Lead III

Your code looks like it should toggle the red led then back to blinking the green led. I have to drive to work now. When I get there I can try it on a dev board. What STM32 are you using and what pins are the leds on?

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.
JGusl.1
Associate II

STM32L072CZTX, im using PB8 and PB9, but its a custom board, not a dev board