Mega 2560 Serialx ports

I have a mega 2560 Arduino board. I am using IDE 1.6.3.

My shield is a prototype PCB with a half duplex RS485 adapter.
The adapter is wired:
Rec Out pin 19
TX in pin 18
The enable pin in connected to pin 2 (TX active HIGH)

The test code is attached.

In the code, I open Serial1. When Serial1 has data in it's buffer,
the Serial.read() function returns a value of 0x00 (zero).

The terminal program was tested on Arduino Uno and the Mega 2560
board using a modified SoftwareSerial code. So I know the serial source is
working.

If the Serial1 port is used to transmit (with pin 2 high), the character code is as expected!

Any suggestion what is wrong with Serial1.read()?

Is it the library, the IDE or am I missing something?

Thanks Steve,

Serial.ino (518 Bytes)

Hi and welcome.

You mentioned an enable pin.
Do you have it wired to a MAX485 (compatible) ?
If so, that one has a DO (Data Out Enable), and a !RE (Not Receive Enable) pin.
These are usually connected together to get either a send or a receive mode.
As you seem to be able to send but not receive, are you sure you have this set up correctly ?
All depends on what RS 485 solution you are using of course.

Steve42:
I have a mega 2560 Arduino board. I am using IDE 1.6.3.

My shield is a prototype PCB with a half duplex RS485 adapter.
The adapter is wired:
Rec Out pin 19
TX in pin 18
The enable pin in connected to pin 2 (TX active HIGH)

Thanks Steve,

Depending on which part you have, you need to connect a pull up on the RX line, if you connect DE/_RE to one pin, when you are in DE (transmit) then R pin is floating. (hi-Z) this will glitch the RX Serial port. Just put a 10k resistor between the RX pin (19) and VCC.

See the attached circuit.

Chuck.


Check out my Kickstarter Project Memory Panes an expansion RAM Shield for Mega2560's. It adds 1MB of RAM for those projects where 8KB is not enough.

Thanks for the comments.

The RS485 adapter is connected properly, the two enables, RE* and DI are connected together.
The enable pin of the Arduino is LOW for receive and HIGH for transmit.

On further investigation, I discovered the serialEvent() function.

I modified my program to use only Serial. funcs with serialEvent(), input was received and echoed
back on Serial channel. serialEvent() was executed and working as expected.

Then I modified the program to read from Serial1, using serialEvent1(). When input was provided
to Serial1, serialEvent1() was NEVER called.

Is there something I must change to get Serial1 and serialEvent1 to work? It acts as the Serialx are not supported on the Mega 2560!

Thanks Steve :confused:

I forgot to mention. I also switched to IDE 1.6.4
Steve42

Steve42:
My shield is a prototype PCB with a half duplex RS485 adapter.
The adapter is wired:
Rec Out pin 19
TX in pin 18
The enable pin in connected to pin 2 (TX active HIGH)

Do you have a second 'adapter' if so wire it to Serial2, connect A-A, B-B. Put Serial1 in Receive, Serial2 in Transmit.

Serial2.print("something out over RS485"); 
while(Serial1.available()){
  char c = Serial1.read();
  Serial.write(c);
  }

Chuck.


Check out my Kickstarter Project Memory Panes an expansion RAM Shield for Mega2560's. It adds 1MB of RAM for those projects where 8KB is not enough.

Ah-oh!

All praise to the Aduirno!

It Serial1 now works! serialEvent1 also works.

I traced all the connection many times. I checked the reference pages many time.

Apparently I did something to my adapter. I don't know if I damaged it or maybe the pc connection
is fubar. I plugged in another module and it WORKS! Just as it should.

Sorry to have posted a few minutes to early! But thank you Chuck for your help!
I really appreciate it!

Steve