Connection, use a resistor 2k2…5k6 in series for every signal:
RPi -> Target MCU
------------------
IO25 -> Reset
IO11 -> SCK
IO10 -> MOSI
IO9 -> MISO
GND -> GND
Install AVRdude (when not already installed):
$ sudo apt-get install avrdude
Edit the file avrdude.conf
and add the following lines under the section PROGRAMMER DEFINITIONS
or download it here:
$ sudo nano /usr/local/etc/avrdude.conf
If the file is empty then use /etc/avrdude.conf
programmer
id = "pi_isp";
desc = "GPIO bitbang";
type = "linuxgpio";
reset = 25;
sck = 11;
mosi = 10;
miso = 9;
;
Download bootloader:
$ wget https://github.com/watterott/RPi-UNO-HAT/raw/master/software/bloader.hex
Flash bootloader:
$ sudo avrdude -c pi_isp -p m328p -e -U flash:w:bloader.hex:i -U lfuse:w:0xFF:m -U hfuse:w:0xD6:m -U efuse:w:0x05:m -U lock:w:0x0F:m
If the programmer is not found, then the cause could be multiple avrdude versions. In this case add the config file as parameter: -C /usr/local/etc/avrdude.conf
A mismatch warning 0xFD != 0x05
on the eFuse can be ignored (choose no). Both values are the same setting, but with a different writing of unused bits.
If the device signature shows 1E 95 14
then use m328
as device name (not m328p).
Connection (Arduino Uno connected to RPi via USB):
Uno -> Target MCU
-----------------
D10 -> Reset
D13 -> SCK
D11 -> MOSI
D12 -> MISO
GND -> GND
Install AVRdude (when not already installed):
$ sudo apt-get install avrdude
Download bootloader and ISP firmware:
$ wget https://github.com/watterott/RPi-UNO-HAT/raw/master/software/bloader.hex
$ wget https://github.com/watterott/RPi-UNO-HAT/raw/master/software/isp.hex
Flash ISP firmware to Arduino Uno (USB device ttyACM0
or ttyUSB0
):
$ avrdude -c arduino -P /dev/ttyUSB0 -b 115200 -p m328p -e -U flash:w:isp.hex:i
Flash bootloader with Arduino Uno (USB device ttyACM0
or ttyUSB0
):
$ avrdude -c stk500v1 -P /dev/ttyUSB0 -b 19200 -p m328p -e -U flash:w:bloader.hex:i -U lfuse:w:0xFF:m -U hfuse:w:0xD6:m -U efuse:w:0x05:m -U lock:w:0x0F:m
A mismatch warning 0xFD != 0x05
on the eFuse can be ignored (choose no). Both values are the same setting, but with a different writing of unused bits.
If the device signature shows 1E 95 14
then use m328
as device name (not m328p).
Auto-Reset for AVRdude needed, see here. The device signature of an ATmega328 is 0x1e950f.
Run:
$ avrdude -c arduino -P /dev/ttyAMA0 -b 57600 -p m328p -v
or (depending on system):
$ avrdude -c arduino -P /dev/ttyS0 -b 57600 -p m328p -v