I have build a RS485 communication between a Mega2560 and Nano. I use on both sites a MAX485 Module.
See the attached schema.
I can upload the code on both arduino's.
The communication is set via a master slave principle, but in a asychronous way.
The master sends a message and listen if the slave responds.
The slave listens for a message from the master and awnser if one received.
It happens in my environment that the communication get stuck. So I build a reset function to reset the slave (nano) aften 10 unanwsered messages. But when I plug in the pin from the master (Mega) into the reset pin on the slave, the communication don't work at all.
Should there be any resistor or other connection
In the schema i'ts the green connector cable.
This maybe nothing to do with your problem but here's a couple of things to check:
It looks like you are using a software serial port to handle the comms. If that's the case, then 28800 baud might be at the upper limits for a software serial port. What happens if you drop the baud rate way down to something like 2400 or 4800?
I can't tell from your code if sendMsg() in sendReader() blocks until the whole message has been transmitted. It's a common mistake when using half duplex RS485 to switch the driver chip back to receive as soon as the message has been passed to the serial software. The bulk of the message is quite likely still in the transmit queue. You need to wait until the transmit buffer is empty before switching back to receive mode. The software serial library should have a flush() function that you can call. It will block until the transmit buffer is empty. Once flush() returns, switch back to receive mode.
I like CAN modules (switch LED from pin GND to pin CS and can replace quartz for fast speeds at 16 MHz, the higher the frequency of the MCP2515, the faster the processing and control):
markd833:
The bulk of the message is quite likely still in the transmit queue. You need to wait until the transmit buffer is empty before switching back to receive mode. The software serial library should have a flush() function that you can call. It will block until the transmit buffer is empty. Once flush() returns, switch back to receive mode.
Hi Mark,
Thanks for the tip I will try that. Perhaps the communication keeps working.
But what if the slave doesn't respond ?
Is there a way to reset the salve (nano in my example) from the master via a connector ?