Mega2560 Tx/Rx problem (as Modbus Master) - Solved

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Mega2560 Tx/Rx problem (as Modbus Master) - Solved

Post by viktor_au »

Setup:
Mega2560 as Modbus Master
Uno as Node13

The problem:
Mega2560 does Tx to Node13, but Tx led does not blink.
I can see on ssd1306 on Node13 that Rx changes from 0 to 1 and Node13 responds and sends the data back, but Mega2560 does show on display only the message 255 - No reply.

What is done:

FC8 is updated.
Mega2560 board is changed to another one. The same result. The direction pin is changed and some other small changers.
But Modbus Master shows no data from Node13.

I have changed the Mega2560 board to Uno board.

Uno is programmed as the Mobus Master (the code is the same, just some small changes to pins, etc).
Uno prints the data OK from Node13.

Got a new Mega2560 board and hooked it up.
The board is re-programmed, but I see no data-in from the Node13.

Is it Rx, Tx on Mega2560 problems?

I can see on the Mega2560 board the Rx led blinks, but no Tx blinking.
What is strange as the Node13 on Uno shows the incoming Rx from Mega2560. It means that Master did send the message to Node13.

Testing: I have removed from the Mega2560 the Rx wire. Rx led on Mega2560 keep blinking, showing that data is coming (or sending?).
What is strange. Looks like the Rx does the job of Tx.

Any help please?
Last edited by viktor_au on Thu Feb 14, 2019 2:00 am, edited 1 time in total.

EtsDriver
Posts: 444
Joined: Tue Apr 15, 2014 4:19 pm
Location: Kajaani, Finland
Has thanked: 345 times
Been thanked: 227 times
Contact:

Re: Mega2560 Tx/Rx problem (as Modbus Master)

Post by EtsDriver »

Could you attach your flowcharts that allow team to reproduce the problem?

Is problem only on modbus master component, or are even normal serial communications affected?
Ill just keep the good work up!

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Mega2560 Tx/Rx problem (as Modbus Master)

Post by viktor_au »

Hi EtsDriver
I have attached three files.
Mega2560 as Modbus master does not read Node13.
Uno as Modbus master reads Node13.
Node13 (based on Uno).
Thank you.
Attachments
Node13_ssd1306(7a).fcfx
(33.48 KiB) Downloaded 223 times
Uno(ModbusMaster).fcfx
(31.75 KiB) Downloaded 224 times
Mega2560(ModbusMaster).fcfx
(38.6 KiB) Downloaded 228 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Mega2560 Tx/Rx problem (as Modbus Master)

Post by Benj »

Hello,

This seems strange. Can you confirm that the Mega is running correctly e.g. the display is working. Also can you confirm that the UART TX and RS485 Data Direction pin are outputting values?

I'll have a dig and see if we have a Mega board available in the office still.

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Mega2560 Tx/Rx problem (as Modbus Master)

Post by viktor_au »

Hello Benj

On photos Uno works as a Modbus Master. The message from Node 13 is just two (samples) numbers:1297.
Master communicates with Node13 with no problems.
Attachments
UnoMastSignA,B.jpg
UnoMastSignA,B.jpg (63.69 KiB) Viewed 23424 times
UnoReadsNode13-1.jpg
UnoReadsNode13-1.jpg (134.92 KiB) Viewed 23424 times

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Mega2560 Tx/Rx problem (as Modbus Master)

Post by viktor_au »

Mega 2560 as Modbus Master

Modbus Master is Mega2560. Mega is connected to Max485 module(s).
Slave 13 is shown as ProMini (on image) but in real life it is based on Uno.
Attachments
Mega_setup_1.jpg
Mega_setup_1.jpg (79.39 KiB) Viewed 23424 times
1_MegaAB_sign.jpg
1_MegaAB_sign.jpg (61.04 KiB) Viewed 23424 times
2_Tx_Rx_Dir.jpg
2_Tx_Rx_Dir.jpg (78.78 KiB) Viewed 23424 times
Last edited by viktor_au on Tue Nov 27, 2018 1:20 am, edited 1 time in total.

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Mega2560 Tx/Rx problem (as Modbus Master)

Post by viktor_au »

Node13 (slave) shows the incoming Rx
Attachments
3_Node13ShowsRx.jpg
3_Node13ShowsRx.jpg (74.46 KiB) Viewed 23424 times

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Mega2560 Tx/Rx problem (as Modbus Master)

Post by viktor_au »

I have changed the Max485 module.
The A,B signals have changed, Node13 receives the Rx from Master, but Master does not 'see' the data from Node13.
Attachments
2_MegaAB_sign.jpg
2_MegaAB_sign.jpg (59.93 KiB) Viewed 23421 times

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Mega2560 Tx/Rx problem (as Modbus Master)

Post by viktor_au »

Mega2560 Rx0 board pin testing

Note: Max485 is disconnected from Mega2560.

Looks like the Tx and Dir work OK.
However the Rx has constant +5v.
Attachments
NoWiresConnected.jpg
NoWiresConnected.jpg (76.21 KiB) Viewed 23391 times

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Mega2560 Tx/Rx problem (as Modbus Master)

Post by viktor_au »

Master Rx should have +5v level until Slave will send this level "down" (?).

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Mega2560 Tx/Rx problem (as Modbus Master)

Post by viktor_au »

Question to Matrix team.

Properties->UART->TX and RX are readable only.
Is it possible to change the properties to writeable so I can check other Mega2560 channels?

EtsDriver
Posts: 444
Joined: Tue Apr 15, 2014 4:19 pm
Location: Kajaani, Finland
Has thanked: 345 times
Been thanked: 227 times
Contact:

Re: Mega2560 Tx/Rx problem (as Modbus Master)

Post by EtsDriver »

viktor_au wrote:Question to Matrix team.

Properties->UART->TX and RX are readable only.
Is it possible to change the properties to writeable so I can check other Mega2560 channels?
Hi viktor!

Make a copy of your program, just before doing following steps:

You should be able to select the AtMega processor (if you own the atmel pack?) that is on board directly (ATMega2560), then you generate compatible .hex (compile) on flowcode and push the file to the bootloader using something like this.

Remember to double check all clockspeeds and other things after change, as now youre controlling the processor directly, without arduino familiar stuff (for example, D13 pin will now be PortB7).

After that, you should be able to select Tx/Rx in the way you want to do!
Ill just keep the good work up!

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Mega2560 Tx/Rx problem (as Modbus Master)

Post by viktor_au »

Thanks EtsDriver.

But I have only Ard licence, not the AVR.
I think Steve_SS uses the Atmel Atmega2560 as the Modbus master without any problems as well.

The question is - why Arduino Mega2560 refuses to Tx, Rx Modbus Master signals properly.
I hope Benj will find the answer (as he said...)

It could be a problem with my hardware setup... maybe I have missed something.
But Arduino Uno works as the Modbus Master OK with the same setup.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Mega2560 Tx/Rx problem (as Modbus Master)

Post by Benj »

Hello,

Can you test the UART comms using the UART (RS232) component.

You can try transmitting from a Uno and receiving from the Mega and visa versa. Ideally we need to nail down what is and isn't working on the Mega and this will help to track down the cause of the problem.

I don't have a Mega 2560 R3 in the office so I've ordered one that should arrive next week.

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Mega2560 Tx/Rx problem (as Modbus Master)

Post by viktor_au »

Ok Benj.
Will do.

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Mega2560 Tx/Rx problem (as Modbus Master)

Post by viktor_au »

Uno to Uno by using Rs232

Works OK.
Tx LED and Rx LED blink OK.
Attachments
diagram_1.png
(63.08 KiB) Downloaded 3691 times
UnoMasterRs232_1.fcfx
(23.52 KiB) Downloaded 131 times
Uno13_ssd1306(78)_Rs232.fcfx
(22.93 KiB) Downloaded 135 times

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Mega2560 Tx/Rx problem (as Modbus Master)

Post by viktor_au »

Mega to Uno

by using Rx232
Mega: Tx0, Rx0 (board pins).
Works OK.
Tx LED and Rx LED blink OK.
Attachments
MegaMasterRs232_1.fcfx
(23.52 KiB) Downloaded 146 times
mega_uno-1.jpg
mega_uno-1.jpg (107.54 KiB) Viewed 23106 times

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Mega2560 Tx/Rx problem (as Modbus Master)

Post by viktor_au »

Question to Matrix team.

Is it possible to update the situation with Mega2560 as Modubs master problems?
Please?

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Mega2560 Tx/Rx problem (as Modbus Master)

Post by Benj »

Hello,

I am still awaiting my Arduino Mega to arrive, actually it's probably about time to start chasing it. I ordered it around the time you opened the topic.

I don't see any reason as to why the Mega isn't working, the UART code works and the Modbus code works so put them together and it should ideally work like it does on the Uno. Without hardware I'm pretty stuck.

Do you have access to any comms analyser tools that you could use to monitor the serial comms as this would give us a good insight into what is going wrong. e.g. monitoring a working system and then comparing with the Mega.

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Mega2560 Tx/Rx problem (as Modbus Master)

Post by viktor_au »

Hello.
Thank you for answering Ben.

As this is my first project with Modbus I have to learn a lot.
I am not sure what comms analyser tools to use.
Any suggestions?

One question Ben.
Is it possible to change the Modbus Master Tx and Rx properties to writable?
Thanks.
Attachments
ModbusMasterComponentRx-1.jpg
ModbusMasterComponentRx-1.jpg (60.04 KiB) Viewed 22713 times

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Mega2560 Tx/Rx problem (as Modbus Master): Solved

Post by viktor_au »

This is hardware issue related to Chinese made Mega 2560.
Matrix component works OK and is not a problem.
--------------------------------------------------------------
Mega 2560 as Modbus Master Rx input

After I used the Schmitt trigger between the R0 (Max485 TTL to RS485 converter output) and Mega Rx input the Modbus started to work.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Mega2560 Tx/Rx problem (as Modbus Master) - Solved

Post by Benj »

Hello,

Excellent that's brilliant news. Glad you got it working and thanks for letting us know.
Is it possible to change the Modbus Master Tx and Rx properties to writable?
No I'm afraid the hardware UART pins are fixed on the Arduino devices unless you use a software channel.

EvgyniyH78
Posts: 1
Joined: Sat Jul 06, 2019 5:20 pm
Contact:

Re: Mega2560 Tx/Rx problem (as Modbus Master): Solved

Post by EvgyniyH78 »

viktor_au wrote:This is hardware issue related to Chinese made Mega 2560.
Matrix component works OK and is not a problem.
--------------------------------------------------------------
Mega 2560 as Modbus Master Rx input

After I used the Schmitt trigger between the R0 (Max485 TTL to RS485 converter output) and Mega Rx input the Modbus started to work.

Good day, I have the same problem, please kindly tell me how and which Schmitt trigger you need to install. I ask if not difficult picture.

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Mega2560 Tx/Rx problem (as Modbus Master) - Solved

Post by viktor_au »

Hello Eugene

I used 74HC14.
Attachments
74HC14-1.jpg
74HC14-1.jpg (68.43 KiB) Viewed 21749 times

Post Reply