Problems in UART communication between ESP32 and STM32

I have a problem with the UART communication between an ESP32 and a STM32. Everything is working fine until I hardreset the ESP32 then I see a frame error on RX and in TX a shift in the response. As soon as I hardreset the STM32 then everything works again and I see the same output as input. Can someone help me?

Best regards

The only solution is to use a communication protocol that require an acknowledgment to every message sent. If no acknowledgement resend the message. Otherwise you personally have to correctly control the sequencing of messages, which you are doing by restarting everything.

Is the serial data in an ad hoc format or in a sentence format?

ad hoc format 2 3 4 5 6 43 2 6 8 5 3 2 4 6 7 8 98 7 65 4 3 32 45 5

sentence format
<1,2,3,4,5,6,7,8,9>

As maybe seen in the ad hoc format the data is just a random format. No telling where one data part is over the other data parts.

As may be seen, in the sentence format the data has a beginning sentence marker, delimited data parts, and an ending sentence marker.

<!,1,2,3,4,5,6,7,8,9>

<@,1,2,3,4,5,6,7,8,9>

<#,1,2,3,4,5,6,7,8,9>
As, also may be seen a data identifier can be placed in the sentence when different data are being sent like temperature or Linear regression data.

Also with the sentence format the code can be wrote that waits on the sentence begin marker to collect the data and a sentence end marker to send the data to a parser.

void fReceiveSerial_LIDAR( void * parameters  )
{
  bool BeginSentence = false;
  sSerial.reserve ( StringBufferSize300 );
  char OneChar;
  for ( ;; )
  {
    EventBits_t xbit = xEventGroupWaitBits (eg, evtReceiveSerial_LIDAR, pdTRUE, pdTRUE, portMAX_DELAY);
    if ( LIDARSerial.available() >= 1 )
    {
      while ( LIDARSerial.available() )
      {
        OneChar = LIDARSerial.read();
        if ( BeginSentence )
        {
          if ( OneChar == ‘>’)
          {
            if ( xSemaphoreTake( sema_ParseLIDAR_ReceivedSerial, xSemaphoreTicksToWait10 ) == pdTRUE )
            {
              xQueueOverwrite( xQ_LIDAR_Display_INFO, ( void * ) &sSerial );
              xEventGroupSetBits( eg, evtParseLIDAR_ReceivedSerial );
              //
            }
            BeginSentence = false;
            break;
          }
          sSerial.concat ( OneChar );
        }
        else
        {
          if ( OneChar == ‘<’ )
          {
            sSerial = “”; // clear string buffer
            BeginSentence = true; // found begining of sentence
          }
        }
      } //  while ( LIDARSerial.available() )
    } //if ( LIDARSerial.available() >= 1 )
    xSemaphoreGive( sema_ReceiveSerial_LIDAR );
  }
  vTaskDelete( NULL );
} //void fReceiveSerial_LIDAR( void * parameters  )

One might be able to discern the use of serial data used in sentence structure from the above code.

Hi Paul,

great, can you share an example code for this solution?

No. With a little thought on your part, you can create code to try.

If one is so inclined to select in the Arduino IDE FILES|Examples|04.Communication one may find several prebuilt examples of the how to do the serial thing.

I added one byte as an ACK indicator. Still I have a framing error which is not handled correctly... The solution you described is not helping me unfortunately...

i have no idea what that means. Did you change the sending program to require a return message acknowledging the receipt of the message it just sent? Did you add code to the receiving program to send back an acknowledge message when a valid message was received?

Yes i did and the error is still remaining once i hardreset the esp32. I guess i have to deal with a correct framing error handler on the STM side...

Very likely. A message with an error should NOT be acknowledged.

Any ideas how you do that on the UART side of the STM32 ? I 'm using a Callback but i assume i need to check the error before i fill my buffer with the data...

I don't know,, as I always do it all myself. Check the documentation for status register values or other status from the callback.

That works but is not so clean:

void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
{
  HAL_UART_Abort_IT(&huart7);
  HAL_UART_Receive_IT (&huart7, UART7_rxBuffer, 3);
  HAL_UART_Transmit_IT (&huart7, UART7_rxBuffer, 3);
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.