I want two atmega32s to communicate over a range of 1000ft, so I decided to use a serial wire for it. I know rs232 is not a good way to communicate over this large range, so I decided to use RS485 which is a balanced pair. For this I want to use MAX485 chips like these.
Now I wrote all the code to use it and got it working for short wire communication with a battery powering my ATmegas (and the MAX485 chips) (I cannot produce the code here as it is for a company where I am just an intern, but as it works in short wire the code is not the problem). What the program basically does is, one atmega sends "Paresh" on serial, the other atmega receives it, does a strcmp if it is indeed recieved as "Paresh" it sends out "Mathur". If the first atmega receives "Mathur" it again sends paresh and the cycle continues.
All this works just fine for serial mode, short wire and on a 6V battery. But as soon as I switch to a CAT-5 cable I get packet loss. I printed what ever one receives on an LCD and after a few cycles (and sometimes even for the first transfer) there is strange strings received. The problems are:
- It works for short wire but not a 30ft CAT-5 cable
- It works for 6V battery but not for 12 volt battery or a 12V adapter.
- It works for normal serial wire upto 10ft but not more than that.
The things I have tried are:
- Added capacitors to fade out any ripples in the supply. (470uf caps).
- Increased delays between switching from transmit to receive modes ( _delay_ms(3); ).
- added caps to the supply to the modules.
- Adding 120ohm terminal resistance to both modules.
What should I do? Please do no suggest any alternatives to the the thing, it would hurt the hacker in me. Why cannot I use an RS485 communication for exactly the purpose it was designed .i.e long distance communication over serial.
Update 1: I used 120ohm terminal resistance. Update 2: I am on a 9600 baudrate.
UUUU...
and verify baud-rate, slew-rate, ringing, etc. \$\endgroup\$