Really basic question about HAL_USART_RxCpltCallback function
Hello everyone!
I'm trying to setup a very basic application and currently have my LPUART Tx and Rx pins tied together. I'm able to run the following code without any issues (well, this is the core of the code with all the initializations stripped out for quick, readability purposes) :
uint8_t TX1_Char = 0x01;
uint8_t RX1_Char = 0x00;
int main(void)
{
while(1)
{
HAL_UART_Transmit(&hlpuart1, &TX1_Char, sizeof(TX1_Char), 100);
HAL_UART_Receive_IT(&hlpuart1, &RX1_Char, 1);
RX1_Char = 0;
HAL_Delay(100);
}
}Obviously, all it's doing is sending TX1_Char (value of 1) to RX1_Char. Pretty straight forward.
What I want to do is have it run the HAL_UART_RECEIVE_IT function from the HAL_USART_RxCpltCallback function and receive it there. So this is essentially what I'm trying to do:
uint8_t TX1_Char = 0x01;
uint8_t RX1_Char = 0x00;
int main(void)
{
while(1)
{
HAL_UART_Transmit(&hlpuart1, &TX1_Char, sizeof(TX1_Char), 100);
//HAL_UART_Receive_IT(&hlpuart1, &RX1_Char, 1);
RX1_Char = 0;
HAL_Delay(100);
}
}
void HAL_USART_RxCpltCallback(UART_HandleTypeDef *huart)
{
HAL_UART_Receive_IT(&hlpuart1, &RX1_Char, 1);
}Unfortunately, I can't seem to get it to call the HAL_USART_RxCpltCallback function . . . I assume my issue is I missed something pretty straight forward (like starting the LPUART interrupt or something to that effect). I have it setup to have a global interrupt for the LPUART with priority 2.
Full disclosure, I did use the *.ioc file to setup most the parameters so it could be a setting issue in the *.ioc file. Regardless, here's my initialization function (if it helps):
static void MX_LPUART1_UART_Init(void)
{
/* USER CODE BEGIN LPUART1_Init 0 */
/* USER CODE END LPUART1_Init 0 */
/* USER CODE BEGIN LPUART1_Init 1 */
/* USER CODE END LPUART1_Init 1 */
hlpuart1.Instance = LPUART1;
hlpuart1.Init.BaudRate = 31250;
hlpuart1.Init.WordLength = UART_WORDLENGTH_8B;
hlpuart1.Init.StopBits = UART_STOPBITS_1;
hlpuart1.Init.Parity = UART_PARITY_NONE;
hlpuart1.Init.Mode = UART_MODE_TX_RX;
hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1;
hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
hlpuart1.FifoMode = UART_FIFOMODE_DISABLE;
if (HAL_UART_Init(&hlpuart1) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN LPUART1_Init 2 */
/* USER CODE END LPUART1_Init 2 */
}As I mentioned above, I removed most the initializations (clock, other peripherals, etc) for readability purposes so if I'm missing something else crucial here that might help resolve this, let me know and I can easily post the full code!
I assume I'm missing something really dumb since this should be a relatively straight forward example . . . Unfortunately, I've been looking through the forums and haven't been able to find the solution so I thought I'd put a post up.
Any info you can give me to help me trigger the HAL_USART_RxCpltCallback function would be greatly appreciated. Thanks!
Oh, and in the odd chance it helps, I'm using an STM32WB55 nucleo development board. Thanks!