Decoding a unkown signal with binary information

hi,
i am trying to decode a signal with a unknown binary information, but i wrote a code to decode it but the code is not working properly. it prints 1 and 0s endlessly.
i have attached a photo of that signal and drive link to the saleac logic session file for you to understand my problems.

in the signal above the first is the start bit which consists 3, 1s.
next the signal between the long 5.04ms pulse and 4.60ms pulse are the information i want to decode in binary format.

Here is the code which i wrote to decode it .

#define receive_pin 2
int first_delay = 418;
int second_delay = 838;

void setup() {
  // put your setup code here, to run once:
  pinMode(receive_pin, INPUT_PULLUP);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  uint32_t received_byte = receive_data(200);
  Serial.print(received_byte,BIN);
  Serial.println();
}

uint32_t receive_data(int no_bits) {
  while (digitalRead(receive_pin) == HIGH) {
    //wait til the signal goes from high to low
  }
  
  delayMicroseconds(first_delay);
  
  uint32_t received_data = 0;
  
  for (int i = 0; i < no_bits; i++) {
    delayMicroseconds(second_delay);
    received_data |= (digitalRead(receive_pin) << i);
  }
  return received_data;
}

what i need is that, is a idea how can i program ardunio to decode the data as 1 and 0.

and thank you for the response in advance :smiling_face_with_three_hearts:
allen_coelho

2 Likes

what microcontroller are you using?
I would look at using an ESP32 using timer interrupts and code similar to a bit-bashed uart receiver

1 Like

Have you tried the different protocols available to you on that analyzer? To me it looks like the output of a PID controller but I am only guessing as I do not have a clue as to what the hardware is.

1 Like

I am using a Arduino Uno. Can't we do the same idea with Arduino Uno instead of esp32

1 Like

The hardware nothing but stm8 microcontroller which sends
data to another microcontroller

1 Like

That makes it very difficult, it can be anything from a sync signal to a lot of information. From the waveform it looks to be very repetitive probably a sync but just a guess. The ST8 is a member of a family of processors, making this even more difficult. Can you post a schematic of the circuit and what it is in? Also which member of the family we are talking about.

possibly - software UARTs operate on the UNO at low baud rates
have you an oscilloscope? can you measure the width of one bit?

I have attached a file of saleac logic analyzer.
It can be sample at the clock signal of 419 microseconds

Sorry, but your code looking a complete nonsense for me...
In the function receive_data you storing a no_bits number of received bits to the variable of uint32_t type:

but in the main code you calling this function with no_bits parameter as much as 200:

What do you expect to get by writing 200 bits into a variable that is only 32 bits long?

  • looks like the stream is HIGH when idle, the start bit will be LOW
  • stop bits will be HIGH guaranteeing that the LOW start bit can be recognized if sent immediately after the preceding data byte
  • knowing the baud rate, the code should wait 1.5 bit periods after detecting the start bit to sample the first bit in the middle of the bit
  • all subsequent bits are sampled by waiting 1.0 bit periods
  • RS-232 Signaling indicates that the the LSB is transmitted first and the the value of the start bit is the value of a high data bit (the data is inverted

if you bit period is 418 (2392 bps ??), then the first_delay should be 627 and the second_delay should be 418 and bits should be inverted

    1 ^ digitalRead (received_pin)

as a test attempted to generate a signal similar to the analyser
transmitting bytes 10101010 11000010 10100101 at 1800baud with a 3mSec delay between bytes I get
image

But sorry for this . I did not understand the reason for u to generate this signal. What are you trying to say??

Can you post the code
u prepared for this test

isn't he doing something similar to what you are doing ... using an oscilloscope to monitor the output of a UART? this can be the output using Serial.write() or Serial.print()

The software PulseView that records the bits has a protocol-decoder which can decode a lot of protocols
https://sigrok.org/wiki/Protocol_decoders

What software did you use to record the signal?
Was it pulseView ?
or
Something else?
I guess PulseView is compatible with Salae because pulseview mentions salae as a usable recording device

user @horace is trying to say
I recorded a signal that looks similar to the signal user @allen_coelho has posted as screenshot
image

The pixel resolutions do not match exactly. This is the reason why I moved parts of horace's screenshot more to the right

This signal that looks similar was created by

User horace did not explicitly say what protocol he used for this transmission
I assume serial = UART

This analysing what the signal is by trying to re-create the same signal using a known protocol

You posted some kind of google-link.
But this link requires authentification so it does not work
all I see is: access denied

This is how I see it: They probably started with Serial/UART at 9600 baud. They probably use software to send and receive the data. Perhaps there are interrupts that take some time, so they had to lower the baudrate to 2400 to make it work.

PulseView has a decoder called "UART", set the Baud rate to 2400 and it should read data.

On the Arduino Uno, a SoftwareSerial port should be able to read the data.

I have changed the setting sorry for that mistake.
The analyser is used is saleac logic analyzer

I understood this.
But with what software running on your computer did you record the signal?
What is the name of the software?