Go Down

Topic: Inserting Start bit and Stop Bit in a serial communicatiom (Read 24085 times) previous topic - next topic

surajveer37

Hello All :)
I am working on a Power line Communications. I want to insert a Start bit and a Stop bit in my Data bits.
Just let me know how to do so? and which library will be included?
Also how to read the data available on the serial that is Starting with my defined Start bit , so that only that data appears over the serial which starts with my desired Start bit?
Any help plz! :-)

AWOL

What's wrong with the start and stop bits put there by the hardware or software UARTs?

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!

AWOL

Quote
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.

GoForSmoke

#4
Sep 23, 2014, 09:51 pm Last Edit: Sep 23, 2014, 09:59 pm by GoForSmoke Reason: 1

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.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

Robin2


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
Two or three hours spent thinking and reading documentation solves most programming problems.

nickgammon


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.

Code: [Select]

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?

http://xyproblem.info/
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Docedison

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
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

MarkT

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?
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

surajveer37

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 :)

PaulS

Quote
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?
The art of getting good answers lies in asking good questions.

steinie44

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?

surajveer37

Code: [Select]

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.

surajveer37

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

AWOL

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.

Go Up