Where to begin communicating with RS232 ?

GeorgeFlorian1
Posts: 106
Joined: Thu Jan 31, 2019 2:32 pm

Where to begin communicating with RS232 ?

Postby GeorgeFlorian1 » Fri Oct 18, 2019 12:04 pm

Hello !

I want to take the readings(output) from a Radar that has RS232 interface using an Olimex ESP32-POE. I am planning to use the UEXT connector of the ESP to connect to the RS232 interface.

The problem is that this is the first project in which I am trying to use the serial communication of the ESP and I have no idea what to write in code.

This is the only relevant piece of code I found:

Code: Select all

#define RXD2 16
#define TXD2 17
char c;
String readString;
void setup() {
  // Note the format for setting a serial port is as follows: Serial2.begin(baud-rate, protocol, RX pin, TX pin);
  Serial.begin(115200);
  Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
  Serial2.println("serial2test");
  Serial.println("Serial Txd is on pin: " + String(TX));
  Serial.println("Serial Rxd is on pin: " + String(RX));

}

void loop() {
  while (Serial2.available()) {
    c = Serial2.read();
    readString += c;
  }
  if (readString.length() > 0) {
    Serial.print(readString);
    Serial2.print(readString);
    //server.print(readString);
    readString = "";
  }
}
Here we can see that GPIO 16 and 17 are used for communicating with the RS232 interface. But, as I previously said, I want to use the UEXT Connector. What pins do I define ? Any advice ?

Can somebody point me in the right way ? Thank you !

mikemoy
Posts: 390
Joined: Fri Jan 12, 2018 9:10 pm

Re: Where to begin communicating with RS232 ?

Postby mikemoy » Fri Oct 18, 2019 2:56 pm

If you want to use the UEXT Connector, get the schematic for the board and locate the TX/RX pins used there, and change your #defines for TX/RX pins.

idahowalker
Posts: 131
Joined: Wed Aug 01, 2018 12:06 pm

Re: Where to begin communicating with RS232 ?

Postby idahowalker » Sun Oct 20, 2019 1:55 am

Greetings.
The way I look at the ESP serial port thingies is that you have 3 serial ports (0), (1,), and (2). Forget about (0), which leaves (1) and (2).

Code: Select all

#include <HardwareSerial.h>
HardwareSerial LIDARSerial ( 2 );
const int SerialDataBits = 115200;
////
void setup()
{
// LIDARSerial.begin ( SerialDataBits, SERIAL_8N1, 26, 25 ); //changes the default pins
LIDARSerial.begin ( SerialDataBits ); //using the default serial pins
}
//// this task is to receive from the serial port
//// triggered every millisecond
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 beginning of sentence
          }
        }
      } //  while ( LIDARSerial.available() )
    } //if ( LIDARSerial.available() >= 1 )
    xSemaphoreGive( sema_ReceiveSerial_LIDAR );
  }
  vTaskDelete( NULL );
} //void fParseSerial( void * parameters  )

Who is online

Users browsing this forum: No registered users and 14 guests