Why UART data is getting corrupted?

Go To Last Post
46 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

I'm getting a strange issue. We have a Atmega 128 controller board that keeps on polling 15 Atmega8 based ultrasonic sensors. They are connected in RS 422 model where all Tx pins of 15 sensors are connected together and in-turn connected to the Rx of the Atmega 128 controller and all Rx pins of 15 sensors are connected together and finally connected to the Atmega 128.. 

Am making sure that the communication protocol is implemented correctly.. I mean.. no data collision among the sensors.. enabling and disabling Tx/Rx links property while exchanging the messages....

 

The problem is.. when I saw the output through the UART on the Atmeg128 controller, the output looks fine.. it is keeping on polling and I saw the below polling message...

01P 02P ......15P

Meaning 01 sensor.. what is the status..., 02 sensor what's the status ..? etc.. and sensors are also properly responding..

 

But when I checked on the next day, either none of them are working or few of them got frozen.

 

When I checked the same UART data,.. I found some scrap message or sometimes no UART data at all... 

And sometimes though Atmega 128 is polling fine, Atmega 8 is not at all responding.. it is mute..

No loose contacts ... 

Why so?

There's watchdog timer running in all Atmega8 and atmega128 also..

What are the typical causes for this strange issue?

Power supply is a 12V dc , meanwhile brand... 

 

 

 

Attachment(s): 

This topic has a solution.
Last Edited: Tue. May 7, 2019 - 02:52 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have deleted your other thread in the ASF forum and moved this to the AVR forum.

 

In the future please post just once in one forum.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I hope you are NOT leaving the lines floating when you disable the TX after transmission.

 

Of course without seeing some code and even a diagram or picture of the boards it's almost impossible to guess. I would start with just one or 2 slaves to begin with and then add more.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi..

Thanks for your quick reply..

Well a strange thing to me is... The same set up is working in a different location ...

We installed those sensors in two shopping malls...

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Intruder195 wrote:

We installed those sensors in two shopping malls...

 

How have you dealt with providing a common line for your RS422? Are your data lines within the common-mode range of your transceivers?

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

Last Edited: Fri. May 3, 2019 - 08:25 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh, and what about line termination and line biasing?

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes....

Termination is provided..

And biasing too is alright..

It is working but after a while am getting some issues

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And the common line?

Perhaps you ought to show a schematic.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Post a real schematic.  Is this RS485 or RS422?  What driver is being used?  What line speed?  What distance?  Alon with bias termination common information.

 

You are only giving us a concept, not a real description.

 

Exact same board used at other location?

 

So. what are the symptoms?  What data do you expect?  What do you get?  Do you read the error bits?

 

js wrote:
I hope you are NOT leaving the lines floating when you disable the TX after transmission.

I've never done RS485 without a transceiver.  [probably neither have you]  We need to know what OP means by "disable the TX", and how  TXE is being handled.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Conceptually your circuit seems ok, but you leave out much detail, and it is in the details where your problem lies. 

So if I understand your issue, the master is polling the slave units, but after awhile the slaves stop responding, is that correct?

How are the remote slaves powered?  Line power or battery power?  Serial comms need stable and accurate clocks, are you using baud friendly xtals on your M8 slaves?

Please post a picture of your slave units.

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If this is in a mall it's also possible you're picking up transients from adjacent high-voltage stuff. I made a DMX receiver and saw random 17V spikes on one of the exposed IO - adding a TVS made for a quick solution.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

UFAnders wrote:

If this is in a mall it's also possible you're picking up transients from adjacent high-voltage stuff. I made a DMX receiver and saw random 17V spikes on one of the exposed IO - adding a TVS made for a quick solution.

 

The TVS won't stop data corruption if its due to pickup from mains wiring. Solution - route your wiring away from mains.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:

Solution - route your wiring away from mains.

 

Or, design it properly.

 

I have a system, designed for a client, that runs high-speed RS485 comms with error-checking but with no automatic resend of corrupt messages. It gets temporarily installed in locations and the comms cables get run alongside, ie often physically touching, mains cables for a length of 200m or more. Result? Zero known instances of corrupt comms over a 5+ year period! How? Proper design.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What was the secret?

 

An installer ran the 485 cable in parallel with a three phase feed to a large refrigerator compressor. The protection circuitry ensured the electronics survived, but the comms surely did get interrupted. There's only so much you can do when the interfering signal is far in excess of the wanted signal.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

An RS422 system I once worked on (design) was in the form of a loop. Devices in the loop added 4 byte messages into distinct time slots. Every device "wiped out" messages it generated when that message came back around the loop. This was designed for control purposes (security system) rather than data transfer. But, it was VERY reliable. Not a checksum anywhere. Every input was TVS protected (lightning in too many places) but that protected from over-voltage, not data errors.

 

VERY reliable but NOT absolutely reliable. Wiring next to an elevator (lift) motor - maybe 5HP - wiped out the system. Had to relocate. There was nothing else practical we could do.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,,..

Can I email you the schematic..?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes.. You are correct..

The slaves stop responding after some time...Not all the slaves but very few of them...

They are powered using the ethernet cable..

Ethernet cable carries Vcc, Ground, Tx and Rx lines..

All the slaves are connected serially..

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes,,..

Your reply makes sense..

Am suspecting the same.. btw.. what is TVS..? sory..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes...
Makes sense..
By the way.. sorry to ask..
What is TVS?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's like out of 100 slaves, 30 slaves are either not at all responding or working only for few days and getting corrupted

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Intruder195 wrote:
Yes...
Makes sense..
By the way.. sorry to ask..
What is TVS?

Google tvs diode

It is used for protecting circuits from transient voltages.

Also be aware of voltage drops - especially on your 0V wire. Ethernet cable has significant resistance. Knowing the current consumption of each of your devices and the lengths ofcable between them, you can estimate the expected voltage drops and quickly determine if they are excessive.

Last Edited: Mon. May 6, 2019 - 03:32 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
Ethernet cable has significant resistance.

So will each Ethernet connector, with 100 devices your looking at ~200 connections (each board has an in/out connection...

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

30 slaves are either not at all responding or working only for few days and getting corrupted

Do the slaves have some self-checking, so that if there is a transient/glitch they restart (reinitialize everything) & return to normal operation (rather than spinning wheels in the weeds)  

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes...
We measured the input voltage at the last slave and made sure that it sufficient which is ~ 10V. Each slave has a 11V r
To 5V regular..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Input voltage is given by the 230V to 12 V SMPS.. Meanwhile brand...
And each slave got a 12V to 5V input regular with appropriate filters..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Critical part is..
They are working fine for few days..
Later
1. Some boards.. code is getting corrupted and they are transmitting some random numbers continuously....
2. Some boards not even transmitting the corrupted data.. They are just mute..
3. Some slaves .. able to receive the UART data... As soon as they receive, LED toggle happens and they supposed to transmit back some character but it is not happening...
No UART transmission...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Main supply lines are far away from the ethernet cable..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes..
But one master and 20 slaves...
Each slaves are connected using the ethernet cable... But inside ethernet cable, we used VCC, ground, Tx+, Tx-,Rx+ and Rx- lines only..
And all of them connected serially..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is you cable screened?

 

Please post a schematic of the slaves.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i will repeat:

Do the slaves have some self-checking, so that if there is a transient/glitch they restart (reinitialize everything) & return to normal operation (rather than spinning wheels in the weeds)  

 

this is NOT the answer:

Input voltage is given by the 230V to 12 V SMPS.. Meanwhile brand...
And each slave got a 12V to 5V input regular with appropriate filters..

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

We can only guess with the information given so far,

but I'd suspect it's a power problem.  Being very far

from the power supply, the regulator on each slave

will need the right capacitors.  For example the 78xx

linear regulators can work without an input capacitor

if physically close to the supply, but need one if too

distant from it.

 

You could try putting a "big" capacitor across the Vcc

and ground at the end of the cable to see if things

improve, though this would only be a test and not an

actual solution.

 

--Mike

 

EDIT: and also check if the Brown Out Detector is

causing resets to occur - the BORF bit in MCUCSR

will be set at startup if a brown out reset the chip.

 

Last Edited: Mon. May 6, 2019 - 09:49 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The OP has neglected to post a schematic, but even then, it needs to work even if the power glitches, sags, becomes intermittent, etc.

 

For example the 78xx linear regulators can work without an input capacitor  if physically close to the supply

 

Never done that, sounds awful--spend a nickle.

Best bet-- always fully filter the input and output (some older vregs, could be damage with giant output caps--feeding back when power removed & fixed by adding a diode. )

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

Never done that, sounds awful--spend a nickle.

 

Agreed, just quoting what's in the datasheet(s).

 

--Mike

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I asked someone would you hook up your LM7805 1 amp regulator with 30 gauge wire?  They said no way, you should use a much heavier gauge wire for good effects & results.

However, they don't think twice when connecting it by laying out using a 6mil trace!!!

 

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Checked the AWG chart and 30 gauge is good for

up to 142 mA, so for a small enough project....

 

21 gauge minimum would be needed for one amp.

 

--Mike

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

attached the Master's schematic

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

 

up to 142 mA, so for a small enough project...

 Perhaps, but bleh...enough ground drops abounding (10-15 mV) to render precision measurements useless.  Hey, my reference level over there is not reading the same over here???!? 

 

A circuit board gave very strange results in a somewhat precision differential app ...I asked the PCB guy why he used such thin power traces (which ran about 8 inches)...he gruffly checked & said said they were rated to carry the current...that means they won't burn up or get too hot, not necessarily forming a solid connection---this was, in fact, the upper limit of the worst allowable connection.

 

 

attached the Master's schematic

 

where?

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

where?

 

Top post.

 

Some comments...

 

1) No line biasing resistors.

2) No separate 0V reference line for the RS422 signals

3) 2 unused cores in the RJ45 connector which could have been used to decrease resistance of the VCC and 0V lines.

 

 

I wonder if we are missing something here?...

 

Intruder195 wrote:

...either none of them are working or few of them got frozen...I found some scrap message or sometimes no UART data at all...though Atmega 128 is polling fine, Atmega 8 is not at all responding.. it is mute...There's watchdog timer running in all Atmega8 and atmega128 also.

 

...I can't help thinking that if the protocol and software was robust enough then the system ought to have recovered even if there had been comms errors.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No separate 0V reference line - its a bit hard to provide this unless the power rails on the slaves are isolated. With no isolation, the potential at the 0V at the end of the line is not the same as the start of the line so what the receiver sees in terms of volts is nothing like what is being sent.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your schematic shows buss termination resistors at each node, disable all but the two units at the ends of the busses!

Too many termination resistors will load the buss and make it unreliable.

 

Jim

 

edit: added note about termination

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274

 

 

 

Last Edited: Tue. May 7, 2019 - 02:42 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The OP has marked post #10 as the solution, based on the posts I think the OP needs to unmark post 10 as its evident the problems are still there.

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your power supply will do nothing...how will the current get to U1 with D1 backwards?

 

Maybe your project is accidentally being powered by the incoming data lines---a definite problem!!

 

Does your led, D2,  come on when the data lines are disconnected?

 

XBEE_TX, will not turn Q1 on/off...that circuit needs reworked.   Their are gates/converter chips that will does 3.3v to 5V conversion for you.

Also, XBEE_TX is an input to the AVR & should be on the left, ATMEGA_RX1 (going TO the avr belongs on the right)

 

Make sure ATMEGA_RX has a pull up (perhaps internal), since it can be floating

U1 gives 5v, U2 gives 3.3v  they ned different part numbers on schem.

 

Why are 120 ohm R6 & R7 drawn somewhere else?  That only makes it harder to follow what you are doing. Don't be too lazy to show them in the proper spot (connected to max 491)

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes..
But am just suspecting...
Might or might not be An exact problem..
It's because it is working at some places and not working in some other places..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Interesting...
Will check and come back

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I noticed on the master on the rj45 you have your AB differential on pins 7/8 which is good, but I see the X/Y is on 5/6 which are two different sets of wire in the cat cable..

Ie. AB set is on the brown twisted set but xy is on the white/blue - orange wires. It's best to keep differential pairs in the same twisted set not split.

I would go vcc pin 1&2
Gnd pins 3&6
Ab pins 4&5 or 7&8
Xy pins 7&8 or 4&5

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

At the risk of repeating myself, and putting aside any hardware issues,...

 

Brian Fairchild wrote:

...I can't help thinking that if the protocol and software was robust enough then the system ought to have recovered even if there had been comms errors.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss