ESP32-EVB + MOD-RS232 to read data from device

Started by roger.peralba, March 31, 2023, 07:08:21 PM

Previous topic - Next topic

roger.peralba

Hi all,

I have an ESP32-EVB and a MOD-RS232 boards. I need to read data from an rfid card device which uses RS232 protocol but I can't achieve it.

Could you help me to know which pins of ESP32 I can use for comunication or if I need to change something at MOD-RS232? I'm using Serial1 as GPIO's 4 and 36.

My code is this:
#include <HardwareSerial.h>
#define RXD 4
#define TXD 36
String readString;
//HardwareSerial Serial1(1); // Configura el puerto serial 1
void setup() {
  Serial.begin(115200); // Inicia el puerto serial para monitorear los datos recibidos
  Serial1.begin(19200, SERIAL_8N1, RXD, TXD); // Inicia el puerto serial 1 con una velocidad de 19200 baudios, 8 bits de datos, sin paridad y 1 bit de stop
  Serial1.println("serial1test");
  Serial.println("Serial Txd is on pin: " + String(TXD));
  Serial.println("Serial Rxd is on pin: " + String(RXD));
}
void loop() {
  //Serial.print("Entrant al loop");
  if (Serial1.available()) { // Si hay datos disponibles en el puerto serial 1
    char c = Serial1.read(); // Lee el siguiente byte de datos
    readString += c;
    Serial.write(c); // Escribe el byte de datos en el puerto serial para su monitoreo
    Serial.print(readString);
  }
  // Verifica si se ha recibido la cadena de texto completa
  if (readString.endsWith("\n")) {
    // Se ha recibido una lĂ­nea completa, imprime la cadena de texto completa y limpia el buffer
    Serial.println("Received string: " + readString);
    readString = "";
  }
}

LubOlimex

For starters it seems like you've swapped RXD and TXD. RXD is pin 36 and TXD is pin 4.

Also are the levels of your RFID device compatible with MOD-RS232?
Technical support and documentation manager at Olimex

roger.peralba

Hi LubOlimex,

Thank you for your response.

I use RXD and TXD in this way because my RS232 device uses RXT to TXD, and TXD to RXD. This is the device I'm using: https://www.hw-group.com/node/9401

I don't have clear some things:
1. Can I connect it directly without MOD-RS232?

2. Which UART uses MOD-RS232? I need to jumper something?

If I'm correct UART0 (GPIO's 1 & 3), UART1 (GPIO'S 4 & 36) and UART2 (GPIO's 17 & 16), is it true? Also I think that I cannot use UART0 because it's used for flash.



Thnak you,
Roger.

LubOlimex

As I already wrote you CAN'T have:

#define RXD 4
#define TXD 36

Because TXD has diode on it and it is not a GPIO pin, it is GPI pin. It can't be TXD, it can be only input. Refer to ESP32-EVB's schematic and check the TXD at the UEXT connector to understand better. Just use the opposite:

#define RXD 36
#define TXD 4

You don't need to touch jumpers by default. The connections between ESP32-EVB and MOD-RS232 are straight forward - GND to GND, 3.3V to 3.3V, pin #3 GPIO4/U1TXD to pin #3 3_TX, pin #4 RXD to pin #4 GPI36/U1RXD.

Notice that MOD-RS232 can't power your target since it requires at least 7.5V, so you need a second power supply for it.

Technical support and documentation manager at Olimex