1

As a volunteer for Public Invention, I have developed an Atmega328 based design in which I thought I was largely duplicating the Arduino UNO. Unlike the UNO, I did choose a CH340 USB to UART chip as that was a part on some UNO clones I have purchased.

Our project, the General Alarm Device, is at: https://github.com/PubInv/general-alarm-device

In the summer of 2022 We built up 15 Verion 1 assemblies. When we went to put boot loader into them we found we could put the Duemilanove bootloader but not the UNO. We do not know why.

Even with the Duemilanove bootloader we from time to time have problems uploading code. Some times the IDE reports a problem but the code uploaded. And perhaps some times we had to try to load more than once. Here is an issue written up after one user had some difficulty with firmware upload: https://github.com/PubInv/general-alarm-device/issues/127

Related questions, Is their a way to check which boot loader is in a board?

Could our root problem have been due to which boot loader was on the UNO we were using as the ICP?

3
  • the difference is the upload baud rate. Duemilanove bootloader uses much slower baud rate. you have some problem with the USB to TTL Serial circuit
    – Juraj
    May 9 at 4:22
  • Hello Juraj, Can you point me to documentation for these baud rates. For what should I google? May 10 at 22:13
  • see the boards.txt file for the AVR platform. (or read in the IDE console the parameters of the upload command)
    – Juraj
    May 11 at 4:18

1 Answer 1

2

Related questions, Is their a way to check which boot loader is in a board?

I wrote some code to detect chip signatures a while ago which also reports on known bootloaders: http://www.gammon.com.au/forum/?id=11633

It really is too long to post here. The code however is at https://github.com/nickgammon/arduino_sketches in particular in the Atmega_Board_Detector folder.

It's the same processor chip, you shouldn't have problems uploading, provided you use the appropriate clock speed and baud rate.

See my answers here:


Where do I learn what is appropriate?

Well, the bootloaders have hard-coded into them the speed at which they expect the serial data to arrive. In the case of Optiboot it is 115200 baud, some other bootloaders may use 9600, 57600 or other speeds.

Now this baud rate is also dependent on the clock rate of the processor, because the baud rate is derived from the system clock.

So for example, on a Uno, Optiboot "expects" (in the sense that a computer can expect anything) that it will be running on a board at 16 MHz, and that the communication will be at 115200 baud.

So, if you are running at 8 MHz (half that speed) then the baud rate will naturally be 57600. However you can compensate for that by editing the file boards.txt in your Arduino installation and changing the baud rate, eg.

uno.name=Arduino Uno

uno.vid.0=0x2341
uno.pid.0=0x0043
uno.vid.1=0x2341
uno.pid.1=0x0001
uno.vid.2=0x2A03
uno.pid.2=0x0043
uno.vid.3=0x2341
uno.pid.3=0x0243

uno.upload.tool=avrdude
uno.upload.protocol=arduino
uno.upload.maximum_size=32256
uno.upload.maximum_data_size=2048
uno.upload.speed=115200

uno.bootloader.tool=avrdude
uno.bootloader.low_fuses=0xFF
uno.bootloader.high_fuses=0xDE
uno.bootloader.extended_fuses=0xFD
uno.bootloader.unlock_bits=0x3F
uno.bootloader.lock_bits=0x0F
uno.bootloader.file=optiboot/optiboot_atmega328.hex

uno.build.mcu=atmega328p
uno.build.f_cpu=16000000L
uno.build.board=AVR_UNO
uno.build.core=arduino
uno.build.variant=standard

Change the line "uno.upload.speed" to read 57600 in this case. That way the program (avrdude) which uploads to the board will upload slower, and since you are running at a slower speed, all will be well.


So, to make it all work:

  • Find which bootloader you have (by comparing signatures) or simply upload a new bootloader of a known type. I have a page about uploading bootloaders which might help you there.

  • Look up (eg. in that file) what the baud rate this particular bootloader uses (eg. 115200 for Optiboot).

  • Set your processor to run at that clock speed with a crystal or resonator. (see the line "uno.build.f_cpu" which is 16000000 in this case).

  • If you choose to run the processor at a different speed (eg. using the internal clock, at 8 MHz) then either use a bootloader designed for 8 MHz, or change the upload speed baud rate line in the file as mentioned above. I suggest copy/pasting an existing entry, changing for example "uno" at the start of each line to "myboard" or something like that, and the "name" line as well, so it will appear in the drop-down menu of available boards).

2
  • Hello Nick, Thanks for the link to the code I hope to try it soon. Regarding "provided you use the appropriate clock speed and baud rate." Where do I learn what is approprate. That is what I am asking about here. I am not afraid to read docuementation but have no idea the key words for which to search. May 10 at 22:12
  • @ForrestErickson See amended answer.
    – Nick Gammon
    May 11 at 6:26

Your Answer

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

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