Page 1 of 1

Serial2, transmit-problems

Posted: Thu Jan 06, 2022 10:42 am
by hertugen
Hello experts.

I have an ESP32-S2 and an external unit, which is wired up to Serial2 (pin 16/17 and CTS on pin 8).
The external unit can be accessed using a built-in USB->UART controller and I can open a terminal and submit HEX-commands, manually.
Now, I disconnect the USB and cun all communication through the ESP32. It seems to work without relying on CTS and the unit also reports back every 30th second, giving a reading. So far, so good.

The problem is, that the unit isn't responding to commands from the ESP-32. As you can see below, it waits 10 seconds and then fires a command (0x09 0x00), which should trigger an immediate response.

I have RealTerm open at COM4 (the ESP32) in order to monitor the communication. After 10 seconds, I see that a "FF" is transmitted and not "09 00". The external unit doesn't respond to this command, so nothing happens.

Any suggestions?

  1. #include "driver/uart.h"
  2. #include <HardwareSerial.h>
  3.  
  4. #define RXD2 16
  5. #define TXD2 17
  6. #define CTS 8
  7. #define BUF_SIZE (1024)
  8.  
  9. void setup() {
  10.  
  11.   Serial.begin(115200);
  12.   Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2); // To peripheral
  13.  
  14.   // Not working when enabled - reason unknown
  15.   //init_uart();
  16.  
  17.   delay(10000);
  18.  
  19.   // Send hex code 09 00 to Serial2. The loop-function should then show an answer, display something like 59 24 FF FF 1A FF FF BD FF FF 1D FF FF BF FF FF BE 00 12 25 FF FF B3 FF FF A3 FF FF 82 FF FF D4 FF FF 78 FF FF F0
  20.   byte message[] = {0x09,0x00};
  21.   Serial2.write(message, sizeof(message));
  22. }
  23.  
  24. void loop() {
  25.     if (Serial2.available()) {
  26.       // Communication works - peridically receiving something like 52 12 00 12 00 09 00 20 00 08 00 00 68 F8 00 00 00 00 00 00
  27.       Serial.print(Serial2.readString());
  28.     }
  29. }
  30.  
  31. void init_uart() {
  32.     const uart_port_t uart_num = UART_NUM_2;
  33.     uart_config_t uart_config = {
  34.         .baud_rate = 115200,
  35.         .data_bits = UART_DATA_8_BITS,
  36.         .parity    = UART_PARITY_DISABLE,
  37.         .stop_bits = UART_STOP_BITS_1,
  38.         .flow_ctrl = UART_HW_FLOWCTRL_DISABLE
  39.     };
  40.    
  41.     //ESP_ERROR_CHECK(uart_param_config(uart_num, &uart_config));
  42.    
  43.     uart_param_config(UART_NUM_2, &uart_config);
  44.     uart_set_pin(UART_NUM_2,UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE,UART_PIN_NO_CHANGE,UART_PIN_NO_CHANGE);
  45.     uart_driver_install(UART_NUM_2, BUF_SIZE * 2, 0, 0, NULL, 0);
  46. }
  47.  
  48.  
  49.