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 08:02 AM
You don't say what mode you're using to receive data. Are you polling, interrupt or DMA?
2022-11-09 08:02 AM
"I am using interrupt mode"
2022-11-09 08:20 AM
post your code for RxCpltCallback().
2022-11-09 08:24 AM
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);
}
}
2022-11-09 08:24 AM
That main loop never changes to the RED_LED loop
2022-11-09 08:39 AM
what kind of UART data are you expecting?
2022-11-09 08:45 AM
Just strings. I'm trying to inject them temporarily using a serial monitor. Im sending strings longer than 20 bytes
2022-11-09 08:51 AM
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?
2022-11-09 08:59 AM
STM32L072CZTX, im using PB8 and PB9, but its a custom board, not a dev board