Can't communicate with Mega 2560 using RS485
Hello again. I am trying to use IND I/O RS485 to communicate with an arduino mega 2560 + MAX485 modules and all I get is gibberish data. I set the D9 on IND I/O to HIGH for transmit mode and pin DE (jumpered to RE) on MAX485 module to LOW for receive mode. Below is wiring of MAX485:
MAX485 Pin
Vcc --> Mega 5V
GND --> Mega GND
R0 --> Mega RX1
DI --> Mega TX1
DE + RE --> Mega Pin 30
A --> IND I/O A
B --> IND I/O B
IND I/O Code as transmitter :
const int pin_485Dir = 9;
const int RS485Transmit = HIGH;
void setup()
{
Serial1.begin(9600);
}
void loop()
{
//Set transmit mode
digitalWrite(pin_485Dir, RS485Transmit);
Serial1.println("Hello World !");
delay(3000);
}
Mega 2560 Code as receiver:
const int pin_LED = 13;
const int pin_485Dir = 30; // RX Enable RS485
const int RS485Transmit = HIGH; // TX Enable RS485
const int RS485Receive = LOW;
void setup()
{
Serial.begin(9600);
Serial1.begin(9600);
pinMode(pin_LED, OUTPUT);
pinMode(pin_485Dir, OUTPUT);
}
void loop()
{
//Set receive mode
digitalWrite(pin_485Dir, RS485Receive);
while (Serial1.available()) {
char ch = Serial1.read();
Serial.print("RX: ");
Serial.print(ch);
Serial.println("");
ToggleLED();
}
}
void ToggleLED() {
digitalWrite(pin_LED, !digitalRead(pin_LED));
}
Note: GND of MAX485 is not connected to IND I/O 485 GND. When I connected them both, data stop appearing at Mega 2560's serial monitor. If I disconnected the GND, gibberish data appear again. I also tried removing the 3 jumpers on IND I/O one by one with no luck (still gibberish data).
MAX485 module:
http://www.chinalctech.com/index.php?_m=mod_product&_a=view&p_id=811
Any help will be greatly appreciated. As last resort, I am thinking to cut off pin 5 of Adum 1402 to disable RS485 and use the IDC pin 3 & 4 for normal Serial communication. Or can I still use the IDC pin 3 & 4 if RS485 is not used ( ie: no cables connected to A and B )?
Update #1: Gosh.. If only you have just one external Interrupt available.. I wouldn't have to deal with this problem. Even better if you don't use i2c for the Indio ports..
Hi Albert,
Can you start with trying to send a byte, as in https://industruino.com/blog/our-news-1/post/rs485-serial-communication-28
What is the jumper position for this case? I left all three jumpers connected.
Ok, I am going to take a shortcut now. Can you please tell me which one is pin 5 on the ADUM1402 chip? I am going to cut it off to enable serial access through IDC 14 pin D0 & D1. Another question, can I use INT on D0 / D1 if I don't use Serial1?
Have a look at MOD1 in https://static.industruino.com/downloads/manuals/GSM_GPRS_for_Industruino_product_manual_April'2017.pdf and pinout diagrams for INTs on D0/D1
Maybe, but this is only my impression, what you started doing is causing you a lot of distress.
You should set some basic rules:
1 do not tamper your Industruino
2 can't think of anything else
From this viewing point, you seem running around catching the next correction, while you should consider the basics under a different point of view.
You started with an interrupt problem, you are ending with several different problems which should not be related to your project.
Sometimes the best thing is to let go and start from scratch again, even if it seems too much work.
But at least it is planned ahead and not a continuous surprise.
Il 12 maggio 2017 alle 10.24 Albert Tobing <albertlt@industruino.com> ha scritto:Ok, I am going to take a shortcut now. Can you please tell me which one is pin 5 on the ADUM1402 chip? I am going to cut it off to enable serial access through IDC 14 pin D0 & D1. Another question, can I use INT on D0 / D1 if I don't use Serial1?
--
Albert Tobing
Sent by Industruino using Odoo
Ok, I've cut off pin no.5 of the chip and there is no way to restore it with my current tool set. I tried sending normal Serial message and the result is MIX between garbage and correct data. First I tried sending "Hello" in 2000ms interval and the result would be sometimes "Hello" sometimes "!@#!@$". I then changed the message to "A" and the result are: AAyAy}AAAAAAAßy. Any thought?
Guess what.. After connecting the IDC GND to Mega GND, all work well now. HAHAHAHAHAHAHA (sorry if inappropriate but I am full of joy now). Looking back, it's weird connecting GND on the RS485 stopped the communication completely. Actually, before I cut off the pin, I also found out that I could use INT3 of the D1 (TX) however on startup there were 7 triggers before the pulse actually went in. Since it is shared, I am afraid it would screw up the count. If it was only triggered on startup, its fine I can clear it up. Do you know what caused the trigger?
Your answer
Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!
Keep Informed
About This Forum
This community is for professionals and enthusiasts of our products and services.
Read GuidelinesQuestion tools
Stats
Asked: 5/11/17, 1:29 PM |
Seen: 14880 times |
Last updated: 5/12/17, 8:13 AM |
I tried the sketch and it's still gibberish. I increased the delay on IND to 10s and I noticed the rate of gibberish received in Mega is very fast like there was no delay in place.