Avrdude – Burn fuses (16 MHz clock out on CLK0 / B0)

Reason

Fuses. There are a couple of user selectable operation modes of the AVR microcontrollers. The fuses can’t be edited in the same way you normally program you Arduino. You will need a hardware AVR programmer, ie the one described here: Arduino as ISP. There are a few GUI softwares that are supposed to do this, but I couldn’t get any of the Mac OS X ones to connect to my Arduino/Genuino Uno, so I used AvrDude from the Terminal.

I wanted to do this in order to get a 16 MHz clock output on the Arduino Digital pin 8 / B0 / CLK0. This signal was to be used as a Reference Clock for the AV9110 Serially Programmable Frequency Generator.

 

Parts list

• AVR Programmer
• Arduino Uno
• AvrDude software

 

Setting (aka Programming) the fuses

Step 1, find out the new fuse settings
Use this site to get the hex numbers for your new fuse settings: http://www.engbedded.com/fusecalc (If you don’t understand the contents of this site you need to read your AVR docs, search the web, or ask yourself if you really need to change any fuses.)

Step 2, burn the fuses with AvrDude

In your shell, type avrdude. (If it says unknown command or similar, you need to CD to the directory where AvrDude is on your Mac.) If it presents a list of AvrDude parameters you’re good to go. This command changes the CKOUT fuse so the system clock is output on B0:

The above settings can be gathered from the output of the Arduino IDE when uploading a sketch to your Arduino. Please turn on “Verbose Output when uploading”.

These are the new fuse settings from http://www.engbedded.com/fusecalc. I was mainly interested in CKOUT = true. Setting the fuses wrongly can make your Arduino unresponsive. Please read up on which fuses NOT to change, prior to experimentation.

Avrdude – Upload hex file to Arduino using ISP / ICSP

Reason

In some cases USB cannot be used to program (upload hex file to) a processor on an Arduino board. One such case is when you are targeting the second processor on an Arduino Uno, the ATMega16u2 whose sole purpose is to cater for USB communication.

Another case arises after we succeeded in reprogramming the USB chip. Since it will become a MIDI communication chip instead, there will be no more USB connectivity, so the main processor (ATMega328p) will also have to be programmed with ISP.

 

Parts list

• Arduino IDE (I used arduino.cc 1.6.7 but any fairly modern will do)
• 2x Arduino Uno R3 (one programmer and one target)
• Hacked ICSP flat cable
• 3x LED / 3x 1k resistors (optional)

More info on the ICSP cable and connections at Nick Gammon’s

 

Using an Arduino board as ISP

Step 1, create an ISP programmer
Locate the ArduinoISP example sketch in the Arduino IDE. Upload it to the Arduino board that is to become the programmer. (The programmer board doesn’t necessarily have to be an Uno.)

Step 2, connect the boards
To upload a hex file to the USB-chip (m16u2 aka ATMega 16u2) on an Arduino Uno, you need to connect the programmer’s ICSP header to the target board’s second ICSP header. (If there is only one 6-pin ICSP-header, you have to get a more expensive target board.)

Step 3, upload hex file

 

Shell command

Uploading a pre-compiled hex file to the m16u2 USB controller on an Arduino Uno R3 board, using avrdude and an “Arduino as ISP”-programmer to target the m16u2.

Example

Using Terminal on Mac OS X
Uploading Hiduino midi firmware
from the folder “jobb/EMS/”
Using the “avrdude” that comes bundled with Arduino IDE
The serial port of the “Arduino as ISP”-programmer is /dev/cu.wchusbserial410

The hard part is to get the paths right. To get some hints, go to the Arduino IDE preferences and turn on “Show verbose output during -> Upload”. Then upload a sketch to an Arduino, and examine the log output.

After uploading the firmware I connected the target board to the computer with a USB cable and had a look in System Report:

Hiduino_in_system_report