2

This is a follow on question from How to reduce serial speed on Arduino bootloader (optiboot) and on the IDE?

I did manage recompile optiboot bootloader to work at 57600 bps and uploaded it to a couple of ATmega328-PUs. I just changed the BAUD_RATE to 57600L in Makefile and recompiled it.

They worked just fine with my Arduino Single Sided Serial (Severino) and a couple of custom standalone Arduino boards with FTDI-like header.

However, I couldn't program the same MCUs using my Arduino Uno R3. When I try to upload a sketch, avrdude just sits there waiting for a response that doesn't come. The output I got is something like this:

avrdude: Version 5.11, compiled on Sep  2 2011 at 19:38:36
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "C:\Users\Ricardo\arduino-1.0.5\hardware/tools/avr/etc/avrdude.conf"

         Using Port                    : \\.\COM3
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Recv: 
avrdude: stk500_getsync(): not in sync: resp=0x00

avrdude done.  Thank you.

Would that have anything to do with the 2nd MCU that acts as the USB driver on the Uno - the ATmega16U2? Do I have to patch it, too?

So, my questions are:

1. Why my recompiled optiboot didn't work with my Arduino Uno R3?

2. What can I do to check what's wrong with the upload process using my new bootloader?

9
  • What do you mean by "you couldn't program the same MCUs using your Uno R3" ? Are you trying to use the Arduino as an ISP to program something else? Are you putting a chip already loaded with this bootloader into your R3 and trying to talk to it there? Apr 3, 2014 at 22:21
  • @ChrisStratton - It's the 2nd option. I burn the modified bootloader into an MCU (using my Uno as ISP), then I remove the ISP circuitry, put that MCU with the modified bootloader into the Uno R3 socket and try to upload a sketch using regular serial programming via USB. The Uno doesn't respond to an upload operation with the MCU with the modified bootloader in the UNO (as its main MCU).
    – Ricardo
    Apr 3, 2014 at 22:24
  • 1
    Can you try this with some other custom baud rate than 57600? Apparently this is special cased in the USB serial firmware; perhaps you should compare to the calculation in your bootloader. See github.com/arduino/Arduino/blob/master/hardware/arduino/… Apr 3, 2014 at 22:29
  • 1
    @ChrisStratton - I couldn't compile the bootloader with any speed below 57600. I started to get compiler errors that I couldn't fix easily. Maybe I should post that problem as a separate question and try harder now that you think there's a way out.
    – Ricardo
    Apr 3, 2014 at 22:35
  • 1
    Basically, 57600 does not divide in 16 MHz nicely when the 8x or 16x oversampling of the hardware UART is taken into account. My gut feeling is that different implementation are using different approximations. If they used the same approximation then even if "wrong" things would be basically fine (especially as the hardware design is similar), but if they are are off in opposite directions it could be unreliable. If you post the exact bootloader source you used we can see for sure - some optiboot source I just looked at seems to actually be using a software UART for 57600. Apr 4, 2014 at 2:27

1 Answer 1

1

Chris Stratton's comments helped me find a workaround for my problem. It looks like the version of optiboot I was working with (see source-code here) doesn't work properly at 57600 BAUD with Arduino Uno without modifications (that I don't know how to make). So I compiled the bootloader with 76800 BAUD, configured the IDE accordingly, and all my boards started to work fine with it.

It is still unclear to me the reason I one can't use 57600 BAUD, but I'm too pragmatic and too little knowledgeable to go after the true answer. So, I'll take Chris' word for it. He said this:

Basically, 57600 does not divide in 16 MHz nicely when the 8x or 16x oversampling of the hardware UART is taken into account. My gut feeling is that different implementation are using different approximations. If they used the same approximation then even if "wrong" things would be basically fine (especially as the hardware design is similar), but if they are are off in opposite directions it could be unreliable. If you post the exact bootloader source you used we can see for sure - some optiboot source I just looked at seems to actually be using a software UART for 57600.

That's the end of it for me.

2
  • 1
    Note I did not say you cannot use 57600, though it seems you may have to modify one end to give them a more closely matching approximation of it. Since the serial blocks on the two chips are similar, this should be fairly straightforward. The problem is the software which configures the similar registers in each is fairly different. Apr 6, 2014 at 0:13
  • @ChrisStratton - Ok. I tried to edit my answer to match what you said, but feel free to edit it yourself if you think you can express it better.
    – Ricardo
    Apr 6, 2014 at 1:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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