2022-11-09 06:32 AM
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.
2022-11-09 09:43 AM
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
2022-11-09 10:16 AM
//__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
2022-11-09 10:31 AM
Well im not even reading a low pin state at any time so something might be setup wrong with my hardware
2022-11-09 11:21 AM
Yeah more than likely you don't have the GPIO's set up correctly.
2022-11-09 11:36 AM
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
2022-11-09 01:24 PM
> 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
2022-11-09 01:32 PM
If this init process doesn't tell me then what's the point of using it
2022-11-09 01:56 PM
2022-11-09 08:20 PM
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