Electron gives serial data when there is no serial data

I have two devices that communicate with eachother using half-duplex one-wire serial. I decided to use a Particle Electron to play man in the middle. So what I did was connect one device to the TX pin of Serial4 and one to the TX pin of Serial5. Next I wrote a loop that simply reads 4 and writes to 5 and vice versa.

I am currently trying to understand what happens here because I see the following behavior:

When powering up the devices (Electron is already powered through USB) I see data incoming on both sides.
When powering off the devices after a while (Electron still powered through USB) I constantly get 1 byte available for reading on the serial ports and when I read it it is zero.
When resetting the Electron with the devices powered off it simply detects no data on both serial ports.

Now my question: why does my Electron detect 1 byte on the Serial port when the devices are powered down if they were powered up before?

Some code:

void setup() {
  Serial.begin(9600);
  Serial4.begin(115200);
  Serial4.halfduplex(true);
  Serial5.begin(115200);
  Serial5.halfduplex(true);
}

void loop(){
  while(Serial5.available()) {
      char data = Serial5.read();
      Serial4.write(data);
    }

  Serial.printf("av:%d\n",Serial4.available());
  while(Serial4.available()) {
        char data = Serial4.read();
        Serial5.write(data);
    }
}

@ir_fuel, the UART protocol is an NRZ (Non Return Zero) protocol. This means that the line is kept high unless data goes low for one baud clock period. When you power off your equipment, the data may be in an odd state (floating), causing the spurious data. One possible way to prevent these is to pull the data line low with a resistor (10K should do). However, there is no guarantee that while powering down, the equipment is not outputting noise or data on the line that is interpreted as a valid data frame by the Electron’s UART.

If the devices use a protocol, then using this protocol, you should be able to catch the spurious data and ignore it.

Thanks!
Yeah that was the plan anyway, to use the checksum bytes and header bytes to see if the data is valid.
But good to know what causes it. I am a software engineer, I know a bit about electronics but 1-wire serial was pretty new to me :slight_smile:

@ir_fuel, 1-wire is not the same as UART (serial) communications. It uses a totally different protocol!

What do you mean @peekay123?
From what I understood I am using serial communication whereby RX and TX are handled by the same wire.

I was referring to your comment! 1-wire is a type of interface.

1 Like

That would be halfduplex UART

1-Wire (or OneWire) is a completely different thing and mixing terms will just confuse people.

Ok, didn’t know that was a thing. I was just referring to 1-wire communication, as in, communication over 1 physical wire.