Skip to content

Instantly share code, notes, and snippets.

@rockavoldy
Last active June 4, 2022 20:15
Show Gist options
  • Save rockavoldy/44bda960443ec511830cd2fb26a2c30d to your computer and use it in GitHub Desktop.
Save rockavoldy/44bda960443ec511830cd2fb26a2c30d to your computer and use it in GitHub Desktop.
Flash atmega328p using Raspberry Pi

Flash atmega328p using Raspberry Pi

  1. Download avrdude, sudo apt install avrdude

  2. Copy avrdude.conf to home cp /etc/avrdude.conf ~/avrdude_gpio.conf

  3. Open avrdude_gpio.conf, and find linuxspi, then change baudrate to 115200

  4. Add below code to the bottom of that file

    # Linux GPIO configuration for avrdude.
    programmer
      id = "pi_1";
      desc = "Use the Linux sysfs interface to bitbang GPIO lines";
      type = "linuxgpio";
      reset = 17;
      sck = 24;
      mosi = 23;
      miso = 18;
    ;   
    
  5. Connect the pin as table below

    ICSP Raspi
    1 (MISO) Pin 12 (GPIO 18)
    2 (5V) Pin 2 (Vcc 5V)
    3 (SCK) Pin 18 (GPIO 24)
    4 (MOSI) Pin 16 (GPIO 23)
    5 (RESET) Pin 11 (GPIO 17)
    6 (GND) Pin 6 or 14 or 20 or 32

    ICSP usually like this (Pin 1 is a boxed pin, and the rest is round

    1 2
    3 4
    5 6

    and For the pinout for Raspberry Pi, please see this pinout.xyz

  6. Now, on home directory where avrdude_gpio.conf exist, use this command to initialize the microcontroller

    sudo avrdude -C avrdude_gpio.conf -c pi_1 -p m328p -V -U lfuse:w:0xff:m -U hfuse:w:0xdb:m -U efuse:w:0xfd:m

    Note: if it say "AVR Device not responding", you need to click reset button when flashing, it should show load for Reading and Writing like below

    avrdude: AVR device initialized and ready to accept instructions
    
    Reading | ################################################## | 100% 0.00s
    
    avrdude: Device signature = 0x1e950f (probably m328p)
    avrdude: reading input file "0xff"
    avrdude: writing lfuse (1 bytes):
    
    Writing | ################################################## | 100% 0.00s
    
    avrdude: 1 bytes of lfuse written
    avrdude: reading input file "0xdb"
    avrdude: writing hfuse (1 bytes):
    
    Writing | ################################################## | 100% 0.00s
    
    avrdude: 1 bytes of hfuse written
    avrdude: reading input file "0xfd"
    avrdude: writing efuse (1 bytes):
    
    Writing | ################################################## | 100% 0.00s
    
    avrdude: 1 bytes of efuse written
    
    avrdude: safemode: Fuses OK (E:FD, H:DB, L:FF)
    
    avrdude done.  Thank you.
  7. When it say done, now it's time to flash the firmware, here i flash firmware for wagiminator/ATmega-Soldering-Station, so i just run this command

    sudo avrdude -C avrdude_gpio.conf -c pi_1 -p m328p -V -U flash:w:SolderingStation2_v1.8.hex

    and it will show like below

    avrdude: AVR device initialized and ready to accept instructions
    
    Reading | ################################################## | 100% 0.00s
    
    avrdude: Device signature = 0x1e950f (probably m328p)
    avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
             To disable this feature, specify the -D option.
    avrdude: erasing chip
    avrdude: reading input file "SolderingStation2_v1.8.hex"
    avrdude: input file SolderingStation2_v1.8.hex auto detected as Intel Hex
    avrdude: writing flash (24006 bytes):
    
    Writing | ################################################## | 100% 13.08s
    
    avrdude: 24006 bytes of flash written
    
    avrdude: safemode: Fuses OK (E:FD, H:DB, L:FF)
    
    avrdude done.  Thank you.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment