Decoding a UART signal with gpio pin

Hi there, i am working on a signal that is similar to a UART signal. But if I connect it to the serial port (rx) to decode, it doesn't so any result. So I tried changing the baud rate. I did not get any results.
So I decided to plug that signal to gpio pin and decode it as 1's and 0's.
But I am not sure how to code for it . Can anyone help me out giving some ideas and a sample example how can I do it

Thanks in advance :cowboy_hat_face::cowboy_hat_face:

What is the source of that signal? Do you have an oscilloscope or logic analyzer?

A simple Serial.print(digitalRead() might be a start.

void loop()
{
  Serial.print(millis());
  Serial.println(digitalRead(yourPin));
}

might be a start. Use a 3rd party terminal program that can log to file. Use the highest possible baudrate for communication with the PC.

Below a more extensive example; it uses state change detection. We assume that the signal is high when there is no transmission (as a UART would be). The code checks if the signal level changes and if that happens it prints a duration and the level; this way you might eventually be able to determine a baudrate. The shortest time will (more than likely) be a bit time.

uint8_t uartBit;      // received
uint8_t prevBit = 1;  // previously received
uint32_t lastTime;    // remember when state change was detected

const uint8_t somePin = 5;  // gpio pin

void setup()
{
  Serial.begin(1000000);  // use the highest baudrate supported by 3rd party terminal program
}

void loop()
{
  uartBit = digitalRead(somePin);
  if(uartBit != prevBit)
  {
    Serial.print(millis() - lastTime);
    Serial.print(" ");
    Serial.println(uartBit);
    prevBit = uartBit;
    lastTime = millis();
  }
}

Code not tested

Signal example

I   S   1   1       3         2     1   P   I
--+   +---+   +---+---+---+       +---+---+-----------
  |   |   |   |           |       |
  +---+   +---+           +---+---+

I = idle
S = start bit
P = stop bit
N = number of unchanged bits

You can e.g. get something like

xxx 1   idle time
100 0
100 1
100 0
300 1
200 1
        nothing here as code waits for a state change
1 Like

Please provide more details of that:

  • How did you determine that it's "similar" to a standard "UART signal"?
  • In what way(s) is it the same as a standard "UART signal"?
  • In what way(s) does it differ from a standard "UART signal"?
  • Do you have any documentation?
  • Do you know the baud rate?

As @sterretje suggests, the first thing to try would be a standard serial terminal - far easier to experiment with different configurations than having to write, rebuild, and download code to an Arduino each time! A logic analyser and/or oscilloscope would be the tools to use next if you can't get any joy with a standard serial terminal

1 Like

Where does this signal come from? Maybe that it is simply inverted? Check what is the idle state of the signal.

1 Like

Without knowing what clock signal is being used to generate your mystery signal, you CANNOT DECODE IT!

It is the indoor to outdoor communication signal of inverter air conditioning

Ah ha! So you do have a clocking signal that you have created to produce that documentation. Now you can figure the Baud rate of the signal.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.