Troubleshooting UART comms issue (I think I'm really close but I'm missing something obvious)
Hello!
I'm creating a basic UART project (using an STM32WB55 development board) to communicate with an external piece of hardware where I'm trying to send 9 bytes of data across and receive data back with an interrupt. It would appear I AM receiving the interrupt when I have the UART TX and RX lines tied together (so, hardware wise, that seems to be working correctly). Below is the code I'm using to send the data:
Here's my init function (called in main)
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 */
}Here's my Tx function (called from another function):
uint8_t UART_txBuffer[10] = {0};
if(HAL_UART_Transmit_IT(&hlpuart1, &UART_txBuffer, 9)!= HAL_OK)
{
Error_Handler();
}Here is my RX interrupt (which is being triggered correctly):
uint8_t UART_rxBuffer[10] = {0};
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)
{
HAL_UART_Receive_IT(&hlpuart1, &UART_rxBuffer, 9);
}So, it looks like my data is being sent correctly (it even triggered my external hardware, which I got no response from when my data was incorrect previously). Me now getting a response from the HW is good news and seems to suggest that I'm sending the correct data (I'll have to sort through if THAT data is correct later on but, for all intents and purposes, I'm just tying the TX and RX lines together for this test).
So, based on this, all signs (to me anyway) point to an issue with the way I'm receiving it.
To be fair, I am getting warnings, which might point to the issue:
warning: passing argument 2 of 'HAL_UART_Transmit_IT' from incompatible pointer type [-Wincompatible-pointer-types]
warning: passing argument 2 of 'HAL_UART_Receive_IT' from incompatible pointer type [-Wincompatible-pointer-types]I can get rid of the warnings by sending it &UART_txBuffer[0] instead, but then I get the error handler (which is obviously less ideal).
I don't have a scope with me currently to check the signals are coming across as expected but, based on the test with the external hardware, it does appear that it's sending correctly. Based on that, I assume it has to do with the way I'm receiving or storing my data. I thought I'd throw a post up in case someone else can point me the right direction. I actually think I'm really close at this point.
Any help you can give me would be greatly appreciated. Thanks!
