Inserting Start bit and Stop Bit in a serial communicatiom

I am actually a beginner!
what does it mean by software UART? i mean there must be some coding in arduino to place start and stop bits? can u help me with coding? and Also how to accept only that data which starts with my defined start bit? others must be rejected!

Also how to accept only that data which starts with my defined start bit? others must be rejected!

A decent UART, hard or soft, will detect the leading edge of the start bit, then wait half a bit period and sample the line again to check that the start bit is still there, then sample at bit period intervals until all data have been received.
It may then check for a valid stop bit.

surajveer37:
I am actually a beginner!
what does it mean by software UART? i mean there must be some coding in arduino to place start and stop bits? can u help me with coding? and Also how to accept only that data which starts with my defined start bit? others must be rejected!

Arduino has a SoftwareSerial library that lets you use 2 pins to send and receive serial communications without a hardware serial port. That library handles all the bits. You only use the functions to read, write or print normally.

A hardware serial port, often a UART (universal asynchronous receiver transmitter) also handles all the bits on its own without CPU attention. Some even have message queue to store received bytes until the CPU can get to them.

Arduino UNO has one UART, usually used by the USB to PC connection. The MEGA has four UARTS. Some other AVR chips that you can build into custom Arduinos have one, two, or more and some have hardware serial ports that are not full UART but still very capable.

None of that covers the SPI port found on most all or maybe all AVR microcontrollers. SPI is very high speed serial.

You don't need to code for any of those now but you should know what hardware you have and can use to choose what library to use and how to wire connection except for the built-in USB that is already wired.

But after that, Serial and SoftwareSerial are used the same for almost all purposes.

PS --

Also not all serial is the same voltages.
Going from 0 to 5V serial on one chip to 0 to 3.3V on another requires "voltage leveling" (another whole topic you can search this site for before asking... you will at least be able to ask better questions if you have any questions at all after reading the wealth of information available) through components or chips.
RS232 serial is -6V to +6V. Commonly we use small chips to interface RS232 and Arduino TTL serial. The MAX232 is such a chip family, very reliable and cheap.

surajveer37:
I am actually a beginner!

It would probably be a big help if you explain why you think you need to insert start and stop bits.

In the normal usage of serial communications with an Arduino these happen automatically and the programmer does not have to worry about them.

Maybe you have something else in mind?

...R

surajveer37:
I am actually a beginner!
what does it mean by software UART? i mean there must be some coding in arduino to place start and stop bits? can u help me with coding? and Also how to accept only that data which starts with my defined start bit? others must be rejected!

A start bit is generally a 0 inserted into a stream of 1s.

eg.

11111110
       ^-- start bit

What do you mean by "my" start bit? Is your zero different from some other zero?

This is another X-Y problem isn't it?

Or the OP perhaps is wanting to identify specific serial communications by a Unique Start Bit... (ie packet header)
Perhaps 2 bytes one for ID/Destination and the other for the actual data exchange...

Doc

Some actual information about the physical layer might be useful - what encoding
is assumed, does it need balanced coding (DC-free)? for example, what exactly
is it?

Actually i am working on power line communication and when i am sending or receiving any data , it is sent as well as received successfully but along with lots of Bugs and errors. Need to remove them and want to receive only the data that i have sent! for that i was thinking to include Start and Stop bits so that Arduino might only accept the tx data and not Bugs!
posting the pic too!
Help me with it plz :slight_smile:

AC power lines.PNG

Actually i am working on power line communication and when i am sending or receiving any data , it is sent as well as received successfully but along with lots of Bugs and errors. Need to remove them and want to receive only the data that i have sent! for that i was thinking to include Start and Stop bits so that Arduino might only accept the tx data and not Bugs!

How about you post some code, instead of a stupid picture of some output?

Looks to me, that you need to send the data in packets. Like a special code or command first. Then your data as fixed number of bytes. Followed by a CRC code or check sum. I take it that this is wireless?


void setup()
{
Serial.begin(9600);
Serial1.begin(9600);
pinMode(13, OUTPUT);
}

void loop()
{
if(Serial1.available())
{
char a=Serial1.read();
if(a=='A')
{
digitalWrite(13, HIGH);
}

if(a=='a')
{
digitalWrite(13, LOW);
}
Serial.print(a);

}

if(Serial.available())
{
char a=Serial.read();
Serial1.print(a);
}
}

This is my code:
Serial is arduino
Serial1 is PLC module.

with that above given code i am sending data from one serial monitor to an other using PLC module and arduino. The problem is , i am receiving a lot of noise at the receiving end as mentioned in the previously posted pic! help me in removing such errors at the receiving end!

Pic is posted here too

AC power lines.PNG

I really don't think this is as simple as adding start and stop bits.
You need to google stuff like correction codes, like Hamming and so on, as well as data comms in low SNR regimes.

i am sending data from one serial monitor to an other using PLC module and arduino.

Over noisy electrical power lines? And, you get noise. I'm shocked. Absolutely shocked, I tell you.

Since it appears that what you send does actually make it across, unmolested and continuous, though mixed in with the noise. The usual solution is to use specific start and end of packet markers to delimit the data. If you send "", instead of "Here is some data", you have away of determining where data vs noise happens.

I think the problem here is the use of language.

What you want is not start and stop BITS but start and stop BYTES

This demo of communicating with a PC shows how to use < and > as start- and end-markers. It assumes you only want to send (or receive) readable characters not including either < or >. This is the same concept as @PaulS has mentioned.

If you need to be able to send every possible byte value the code at the start of the same Thread demonstrates a way to do that.

You may also (I hope) have noticed that it is a good idea to check the Forum regularly so as to answer any questions as soon as possible.

...R

OK, it's PLC witch is worse then wireless. Use PaulS example. Also put the Serial.print(a); inside the if statement. Then you won't see the garbage.

 if(Serial1.available())
  {
    char a=Serial1.read();
    if(a=='A')
    {
      digitalWrite(13, HIGH);
    }
   
    if(a=='a')
    {
      digitalWrite(13, LOW);
    }
    Serial.print(a);
   
  }
 if(Serial1.available())
  {
    char a=Serial1.read();
    if(a=='A')
    {
      digitalWrite(13, HIGH);
      Serial.print(a);
    }
   
    if(a=='a')
    {
      digitalWrite(13, LOW);
       Serial.print(a);
    }
   
  }

'a' and 'A' differ only by a single bit - in a noisy environment, that leaves scope for misinterpretation due to corruption by noise.

i am trying to google it since many days.. can't come up with anything yet!

i am trying to google it

I googled "it" and got bazillions of hits. Perhaps you need to be a bit clearer on what you are trying to google, and why.

well @Paul are you trying to say that i should try to send the data inside of these signs "< >" from my serial monitor? and that's it?