RS485 library by Gammon - not working for Arduino MEGA :(

Hi,

have a problem: I made a RS485 communication between two Arduino UNOs. It is working perfect. I want to do the same for Arduino MEGA but it doesn't wanna work :( and this is not working only as a reciver. So I can send data with my Arduino MEGA and receive it by UNO but as soon as I will install MEGA as a receiver than I can not pick up the data...

What can be wrong? The pins are the same for UNO and MEGA (wanted to avoid faults).

Please help because I have no idea why....

Here is link to the library and description: http://www.gammon.com.au/forum/?id=11428

I have check right now that if I will send from MEGA TX0 and RX0 to UNO than it is working. But if I will send from TX1 and TX2 than not. Signal is going out because I see it on osciloscope...

So show us your code! With that library you have to provide callback functions (from what I just read), and I suspect you've done it wrong.

my code is exactly like on that page:

http://www.gammon.com.au/forum/?id=11428

I did not change it...

Makes me crazy...

MEGA to UNO: RX0 TX0 to RX TX is working RX1 TX1 to RX TX NOT working RX2 TX2 to RX TX NOT working RX3 TX3 to RX TX NOT working

UNO to UNO RX TX to RX TX is working

MEGA to MEGA: every combination NOT working

of course I change everytime this two lines in library:

const byte STX = '\45'; const byte ETX = '\46';

this must be some hardware problem... some difference between UNO and MEGA

Don't know if this is the problem, but if you are using the SoftwareSerial library, you must follow this:

Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).

https://www.arduino.cc/en/Reference/SoftwareSerial

this is very helpful, I have found it too and test it... but it is also not working. For example I use pin 1 as TX (it doesn't matter because I wanna receive only) and have try to use pin 10 or 50 but still my MEGA is not receiving... Should I use pullup resistor for RX? 10k Ohm to +5V ???

I think I know it - this is hardware problem, there should be pull up resistor on RX and RX must be one of the pins from : 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).

This is why it is working on UNO because on UNO RX is supported and there is 1k resistor to 5V but on MEGA we need to use another pin for RX which is not pulled to 5V.

Can anyone confirm this before I will damage my ARDUINO? :) Should I use 1k or more?

You shouldn't need a pullup resistor, but it won't hurt anything if you use a 1K resistor as a test. The TX line on the remote device should source and sink current.

I give up... not working even with resistor on pin 10 for RX in library this is 23, so everything ok in software.

Any ideas what else?

An o-scope would be helpful at this point.

I have it, and I see that my signal is comming on RX so receiver get it. Signal is nice, 5V amplitude and sharp. Everything looks good. Just my receiver doesn't wanna receive it...

to have a clear situation:

in software in receiver I need to change only this:

SoftwareSerial rs485 (10, 1); // receive pin, transmit pin

an is correct 10 is my RX like in spec.

In library I have than:

const byte STX = '\23'; const byte ETX = '\3';

23 because this is my pin 10 and 3 because this is my pin 1

Maybe Nick Gammon will show up soon and help you out.

would be nice because I am getting crazy here... don't get it also why when I send from Mego to UNO from other port than RX0 and TX0 than is also not receiving. On o-scope I se that signal is going out and receiver side (UNO) is the same so why it is not receiving...

prepond: to have a clear situation:

in software in receiver I need to change only this:

SoftwareSerial rs485 (10, 1); // receive pin, transmit pin

an is correct 10 is my RX like in spec.

In library I have than:

const byte STX = '\23'; const byte ETX = '\3';

23 because this is my pin 10 and 3 because this is my pin 1

You have four hardware serial ports on a Mega; why are you using software serial?

And why do you use a hardware serial pin (1) in combination with another pin for software serial. I have the suspicion that you don't know what you're doing (no offense intended).

Can you please post your complete code?

I use software serial as on that page:

http://www.gammon.com.au/forum/?id=11428

it is working with software serial so why not?

And question two, why such a combination? Because:

"Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69)."

Have you tried the hardware serial, like Serial1? You need to be a bit flexible if you want to work with these.

this is good idea, I will try it and give report :slight_smile:

So it is like that:

for hardware serial my MEGA can send data to UNO - it doesn't matter if this is TX0, TX1, TX2 or TX3 but the speed is much more lower and I have change delay (in us) from 660 to 3660:

digitalWrite (ENABLE_PIN, HIGH); // enable sending sendMsg (fWrite, msg, sizeof msg); delayMicroseconds (3660); digitalWrite (ENABLE_PIN, LOW); // disable sending

of course this is a little bit too much and could be lower but want to be shure that everything is going out before ENABLE pin is low.

But when I wanna receive it with MEGA also MEGA to MEGA than it is not working.... crazy...