0
\$\begingroup\$

I want to use the hardware serial port (pin 0 RX and 1 TX) to connect a MAX485 IC. Internally these pins are also connected to the onboard USB to serial converter microcontroller which is used to flash the ATMega328 using the bootstrap code.

enter image description here

I know I can't have two different serial devices (USB and MAX485 in that case) at the same time without interfering each other. Given that I want to use the HardwareSerial and not a solution based on SoftwareSerial I have added two jumpers on my design that let me connect and disconnect the MAX485 to the RX pin 0 and TX pin 1 if I want to upload a new sketch.

I have two questions:

  • Is there an elegant way to reduce the two jumpers TX and RX to just one that when shorted connects or desconects both pins at the same time (max RX and TX to pin 0 and 1 on the Arduino)
  • Is it possible to use a transistor software controlled by an arduino pin to have the same efect and let me choose when I want the max485 connected and when I want to fallback to the arduino USB to ttl?

The idea is that if the device is reseted by the computer to upload a new sketch the USB device will be active, once the device has booted as part of the boot process will enable the MAX device and the built in USB will be disabled as the MAX IC will have preference.

\$\endgroup\$
  • 1
    \$\begingroup\$ You probably don't need to disconnect the TX \$\endgroup\$ – immibis Aug 2 '18 at 23:19
0
\$\begingroup\$

There is no need to add extra active circuitry for this.

The MAX485 has a Receive Enable (/RE) pin. You can connect this to a GPIO with a pull-up resistor, so that it will be disabled when that pin is unconfigured during bootloader operation. Once your application program starts up, it can configure the enable pin as an output and drive it low to enable the receive side of the MAX485, which will overpower the series resistor in the ATmega16u2 path.

Since an RS845 bus normally needs explicit transmit enable, you presumably already have the MAX485 transmit enable (DE) wired to a GPIO. Just keep in mind that unlike /RE, DE is active high, so to make it disabled by default, you'd need a pull-down resistor.

\$\endgroup\$
  • \$\begingroup\$ I have a pair of max485 to have full duplex communication. one i always listening and the other is always in receive mode. if I understood I have to put the TX to listen and the RX to transmit so both will be disabled. \$\endgroup\$ – Marc Aug 2 '18 at 23:59
  • \$\begingroup\$ No. You do not want to switch devices to the opposite mode, rather you should simply disable them entirely. \$\endgroup\$ – Chris Stratton Aug 3 '18 at 2:04
  • \$\begingroup\$ Ah ok I see, so I will need two GPIO pins, one with a pull-up and another with a pull-down to enable both MAX485 when I want to use that functionality and 'disable' the USB once the arduino has finished booting \$\endgroup\$ – Marc Aug 3 '18 at 2:54
  • \$\begingroup\$ Depends if in your application you need to disable the transmit side or not. If not you can use only one. Or you can use one with an external inverter. \$\endgroup\$ – Chris Stratton Aug 3 '18 at 7:28
  • 1
    \$\begingroup\$ Yes, you can disable both with one signal by using an inverter. If you need to keep the traffic of the 485 network depends on if other things on that will be confused by it or misoperate as a result of it. \$\endgroup\$ – Chris Stratton Aug 3 '18 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.