Skip to main content
JGusl.1
Associate
November 9, 2022
Question

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

  • November 9, 2022
  • 18 replies
  • 2783 views

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.

This topic has been closed for replies.

18 replies

JGusl.1
JGusl.1Author
Associate
November 9, 2022
	//__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
JGusl.1Author
Associate
November 9, 2022

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

Karl Yamashita
Principal
November 9, 2022

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

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
JGusl.1
JGusl.1Author
Associate
November 9, 2022
 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

waclawek.jan
Super User
November 9, 2022

> 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​

JGusl.1
JGusl.1Author
Associate
November 9, 2022

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

waclawek.jan
Super User
November 10, 2022

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​