I'm using an RS232 to UART converter to control a device from a LoLin NodeMCU V3 ESP8266's Tx0 and Rx0 UART.
My problem is that the LoLin ESP8266 board use the same Tx0 and RX0 UART port to communicate with the embeded CH341 USB/UART chip.
As I use the USB port to program the board and also retrieve some other data, I think having these 2 devices on the same UART is the source of my problem as it sometime doesn't respond as espected.
I've seen the ESP8266 has 2 UART, but the second UART witch is on TX1 and RX1, Rx1 is also used for "the flash chip", thus that UART cannot retrieve data, witch I need to.
Would it there a solution to achieve with no disturbance what I need to do ?
That solution seems quite interesting but I don't feel able to put it in action without code example or explication.
Anywhere I could find some example using it ?
I have in mind that software UART isn't reliable. But I don't remember where I got that information from and I might be wrong ???
hary:
That solution seems quite interesting but I don't feel able to put it in action without code example or explication.
Anywhere I could find some example using it ?
I have in mind that software UART isn't reliable. But I don't remember where I got that information from and I might be wrong ???
Serial.swap(15);
in setup()
esp8266 SoftwareSerial was not reliable in the past. now it is OK
I made that piece of code using the Serial.swap() but it seem to still output the data on the wrong serial port/pin (usual one).
I can still see that information coming on the serial monitor when it 's supposed to be sent on GPIO15 instead of GPIO1 !
void request_inverter_state(const int &periodicite_request = 10000)
{
static unsigned long last_request = 0;
if (now - last_request > periodicite_request)
{
Serial.swap();
Serial.write("\rQ1\r");
Serial.swap();
Serial.println("inverter_state requested");
info_flag = 1;
last_request = now;
}
if (info_flag)
{
char c = ' ';
int length = 40;
char state [41];
char termChar = 13; //CR is 13 DEC on ASCII table
byte index = 0;
boolean haveNewData = false;
Serial.swap();
if (Serial.available())
{
c = Serial.read();
if (c != termChar)
{
state[index] = c;
index = index + 1;
}
else
{
state[index] = '\0';
index = 0;
haveNewData = true;
info_flag = 0;
}
}
Serial.swap();
if (haveNewData)
{
Serial.println (state);
client.publish("inverter/state", state);
haveNewData = 0;
}
}
}
Is there something I'm not doing correctly ? Plus, it sometime mess up my serial monitor !
Sorry, but I don't understand you insist with swap(15).
I don't see what you mean even rereading the documentation at the given link.
I can read :
Serial uses UART0, which is mapped to pins GPIO1 (TX) and GPIO3 (RX). Serial may be
remapped to GPIO15 (TX) and GPIO13 (RX) by calling Serial.swap() after Serial.begin. Calling
swap again maps UART0 back to GPIO1 and GPIO3.
And that's what my code do. Of course, I'm not a programmer and may miss something !