Missing Characters in Response from AT+CWLAP Command using UART DMA
Hello everyone,
I’m currently working on a project where I’m using an STM32H7B3I-DK board to communicate with Esp8266 WIFI Module using AT commands. I’ve been able to successfully send commands and receive responses using HAL_UARTEx_RxEventCallback , but I’ve encountered an issue with the AT+CWLAP command.
When I send the AT+CWLAP command, On my Serial Port I receive this :

But in my Rx Buffer the first few characters of the response are missing. Here’s an example of what I’m seeing:
\r\nOK\r\n", '\0' <repeats 30 times>, "Ooredoo 4G_39D94B\",-67,\"c8:ea:f8:39:d9:4b\",11,-1,-1,4,4,7,0)\r\n\r\nOK\r\n", '\0' <repeats 1943 times>
As you can see, the response begins with a series of null characters (\0) and the first +CWLAP: is missing.
Here are some things I’ve already tried to resolve the issue:
- I’ve disabled the echo of the AT commands using the ATE0 command.
- I’ve checked the UART baud rate and it matches the baud rate of the WiFi module.
- I’ve tried both Normal and Circular Mode.
Despite these steps, the issue persists. My Code is the following:
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size){
if (huart->Instance == USART2)
{
oldPos = newPos; // Update the last position before copying new data
/* If the data in large and it is about to exceed the buffer size, we have to route it to the start of the buffer
* This is to maintain the circular buffer
* The old data in the main buffer will be overlapped
*/
if (oldPos+Size > MainBuf_SIZE) // If the current position + new data size is greater than the main buffer
{
uint16_t datatocopy = MainBuf_SIZE-oldPos; // find out how much space is left in the main buffer
memcpy ((uint8_t *)MainBuf+oldPos, AT_Response, datatocopy); // copy data in that remaining space
oldPos = 0; // point to the start of the buffer
memcpy ((uint8_t *)MainBuf, (uint8_t *)AT_Response+datatocopy, (Size-datatocopy)); // copy the remaining data
newPos = (Size-datatocopy); // update the position
}
else
{
memcpy ((uint8_t *)MainBuf+oldPos, AT_Response, Size);
newPos = Size+oldPos;
}
/* start the DMA again */
HAL_UARTEx_ReceiveToIdle_DMA(&huart2, (uint8_t *) AT_Response, ATBuf_SIZE-newPos);
__HAL_DMA_DISABLE_IT(&hdma_usart2_rx, DMA_IT_HT);
}
}
I would appreciate any help or suggestions on how to resolve this issue. Thank you in advance!
