Serial.print output corrupt

HardyM
Posts: 6
Joined: Fri Oct 29, 2021 10:27 pm

Serial.print output corrupt

Postby HardyM » Fri Oct 29, 2021 11:09 pm

Hi All. Having trouble with serial output on my ESP32-CAM device.
I have two of them setup connected together with TX & RX joined, and I have another device with two serial ports that I can see whats being sent from both devices simultaneously.
All commands send between are prefixed with ESP_ and all lines are standard termination with Linefeed like from println()
I have a command processor that ignores anything without the ESP_ prefix, so I get debugging info and console without interference.
I load the same code into both devices, and the one that detects an SD card attached becomes module number 1.

Now - here's the (summarised view) of the setup code and output.
The systems stand alone work fine. I can issue commands and instruct and switch LEDs, take photos, get status etc.
When I join them, sometimes they get stuck at boot.
The serial output from the setup() code within 2-3 lines of code, already has corrupt serial transmission. (I'm running at 115200 baud)

Here's the output log example. Left is module 1 transmissions and number 2 on the right.
  1. 1:     debug:Running as module number 1.
  2. 1:     No log detected yet
  3. 1:     Set Log=exists
  4.                                                                                     2:     debug:Cam setup done.
  5.                                                                                     2:     ESP_LOG=Cam setup done.
  6. 1:     Listing directory: /
  7.                                                                                     2:     debug:Module 2 ready to serve...
  8. 1:       DIR : /System Volume Information
  9. 1:       FILE: /index.html  SIZE:2 1048576
  10. 1:       FILE: /foo.txt  SIZE: 52file: Setting time: Mon Nov  1 12:00:
  11. 1:     debug:Wifi begin
  12.                                                                                     2:     ESP_LOG=Module 2 ready to servTotal heap:  303272   Free heap:  219396   Total PSRAM: 4194220   Free PSRAM: 3426220
  13. 1:     .-debug:Time init finished
  14. 1:     Monday, November 01 2021 22:00:02
  15. 1:     debug:got time
  16. 1:     Wifi RSSI=-51
  17. 1:     debug:Cam setup done.
  18. 1:     debug:Go Green
  19. 1:     Starting web server on port: '80'
  20. 1:     Total heap:  300832   Free heap:  129220   Total PSRAM: 4194220   Free PSRAM: 3426220
  21. 1:     Ready! Use 'http://10.101.196.63' to connect
  22. 1:     debug:Module 1 ready to TX/RX with other module
  23.  

and the code that generates it
  1.  
  2. void showMem()
  3. {
  4.  return;
  5.   Serial.printf("Total heap: %7d   ", ESP.getHeapSize());
  6.   Serial.printf("Free heap: %7d   ", ESP.getFreeHeap());
  7.   Serial.printf("Total PSRAM: %7d   ", ESP.getPsramSize());
  8.   Serial.printf("Free PSRAM: %7d\n", ESP.getFreePsram());
  9. }
  10.  
  11. void debug(char *txt)
  12. {
  13.   Serial.printf("debug:%s\n",txt);
  14.   if (moduleNumber==2) {
  15.     // Send it for number 1 for logging
  16.     Serial.printf("ESP_LOG=%s\n",txt);
  17.   } else {
  18.     sdAppendLog(txt);
  19.     sdAppendLog("\n");
  20.   }
  21. }
  22.  
  23. //  Heaps of other stuff here like Wifi setup, Camera setup etc.
  24.  
  25. setup()
  26. {
  27.   if (moduleNumber==1) {
  28.     sd_init();
  29.     sd_listdir();
  30.     startCameraServer();
  31.     showMem();
  32.     Serial.print("Ready! Use 'http://");
  33.     Serial.print(WiFi.localIP());
  34.     Serial.println("' to connect");
  35.     delay(2000);
  36.     debug("Module 1 ready to TX/RX with other module");
  37.     sendCmd("ESP_LED1=008000");
  38.   } else {
  39. debug("Module 2 ready to serve...");
  40.   delay(200);
  41.   showMem();
  42.   delay(200);
  43.   lastTimeCheck=millis(); // Init timer
  44.   }
  45. } // End of SETUP()
  46.  
The last debug() command. Module 2 sends "Module 2 ready to server... message. The debug code sends this and then a couple of lines later sends it again with the command for Module to actually log this to sdCard..
But the second ourput is corrupted at the end by the showMem() output that comes next near the end of setup().

If there some buffer / flow control management I need in my serial prints ?
Coming from the old RS232 days I would day yes, but I can't believe that such a small amount of text being sent would cause issues here. And I also assumed that the Arduino Serial.print functions would handle this

Immediately following that last transmit from module 2, it seems to hang and not respond to further commands. But if I disconnect the two serial lines they continue to startup and run and will accept commands from my serial console.

Anyone with thoughts - I'd really like to hear it.

Thanks
And sorry for the messy code.
Hardy

HardyM
Posts: 6
Joined: Fri Oct 29, 2021 10:27 pm

Re: Serial.print output corrupt

Postby HardyM » Sun Oct 31, 2021 9:23 pm

ok. Seems its' an issue with my serial box. Ignore this please folks.

Who is online

Users browsing this forum: No registered users and 44 guests