Upload of sketch via RS232 serial (pin 0)

I would like to be able to upload sketches to an Arduino Uno via RS232 cable. I am developing an engine monitoring system for a boat, and want to be able to maintain it from a remote navigation station.

My understanding is that uploading via this route is feasible?

I have set up a USB RS232 serial adapter on the computer, and a level changer at the Arduino end. This receives data from the Arduino sketch quite happily on the computer monitor at 9600 baud.

However the upload fails. Trying to revert to the USB connection (with the serial cable in place) results in a similar failure (does not sync - 10 retries), but when the serial cable is disconnected, it works satisfactorily.

Transcribed from another machine:

avrdude: Version 6.3, compiled on Jan 17 2017 .....

                System wide configuration file is "home/john....avrdude.conf"
                User configuration file is "home/john/.avrduderc"
                User configuration file does not exist or is not a regular file, skipping

                Using Port                          :/dev/tty/ACM0
                Using programmer            :arduino
                Overriding Baud Rate        : 115200

  avrddude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
                 (10 times)
avrdude done. Thank you. 

An error occurred while uploading the sketch.

It seems to me that the running sketch is driving the interface at 9600 baud, and therefore the attempt at 115200 is failing, perhaps? But that doesn't explain why it stops the USB direct cable from working. There is no discernible flashing on the Rx LED on the Uno.

Does the bootstrap look at the serial interface first?

Do I need a user configuration file?

The first step of an upload is to reset the microcontroller. This activates the bootloader code, which listens for an upload to start for a short amount of time. If no upload starts the bootloader times out and exits to the user application code. When you do a USB upload it automatically resets the microcontroller at just the right time. If you don't have an auto-reset circuit then you need to manually reset the microcontroller just as the upload starts (after the compilation finishes).

1 Like

Thanks..

That would be almost impossible to do remotely? It is quite a big sketch and takes several moments to compile before the upload begins.

What about having the application monitor the Rx channel, sending it a 'reset' command, driving a digital i/o pin high, connected to the reset line on the microcontroller?

Even so, it might be up and running again by the time the upload can get going.

Is there a more intelligent way that the bootstrap can sit and wait for an upload to start?

Why does the presence of the Rx line on pin 0 apparently stop the upload from occurring?

RS232 has more signals than RX and TX. I'm a bit confused if it is the DTR signal or the CTS signal that one needs (pin on 16U2 is CTS, signal in the schematic is called DTR), but you can use that for the reset, just like the USB connection would do it.

You will need an RS232-to-ttl adaptor that has more than only RX and TX. And your USB-to-RS232 obviouysly needs to support it as well.

To my knowledge, you need both RX and TX for upload, only RX will not work.

Sketch uploading works at 115200 baud. It is hard-coded speed in the bootloader as default for UNO (also for others). To change the speed, it means to compile/build a new bootloader image and upload it to the Arduino via ISP.
USB is de facto also serial way, it uses on-board USB/serial transceiver.
Use of extra serial line means not only to have 3 signal lines (Rx, Tx and DTR or RTS for RESET), there is needed impedance matching on ATmega's serial port otherwise no one USB and RS232 will not work.