Nov.10

Burning ATmega 328P-PU boot loader from Raspberry PI

Hi Friends. Welcome to new blog design.I lost all my old blog entries bcoz of server migration.Also this is my 1st post after moving to new company.before all my topics was related to Linux . nowadays I am too much interested in doing electronics projects with AVR.

I took 2 Arduino’s from india and all of sudden one of then is not responding to IDE instructions. Then i was digging through forums and finally came to know that it’s because of corrupted boot loader.I requested some sample chips from Atmel, and they send nearly 6 ATmega 328p chips to my kuwait home address.i thought of install bootloader to the new chips so that i can re use my Arduino.

 

BootLoader:
Microcontrollers are usually programmed through a programmer. This is a piece of hardware you’ll have to make or build…. Unless…. you have a program in your microcontroller that allows installing new firmware without such an external programmer. This piece of software is called a bootloader.

when i started reading this, i thought of install bootloader from another Arduino board. I tried Arduino as ISP method on IDE and that method got failed.Then i tried with my USBAsp programmer, same issue. i am always getting error message on IDE that chip is not responding. And in my connection, i used 15.468 MHZ crystal instead of 16. The thing is it’s very difficult to find electronics components in Kuwait. Also sometimes we won’t get items shipped from out side .

finally i managed to get 2 16 MHZ crystal from one local store.i wired the circuit. and the details are below.

 

The In System Programming (ISP) method is the one I recommend to use with the Raspberry Pi. The down-side is that during program development of the code you are running in the ATmega, you need to use 4 GPIO pins on the Pi. You can pick (almost) any 4, but I suggest you use 4 of the 5 pins dedicated to the SPI interface.

 

To use the Arduino IDE with the Raspberry Pi, you will need to make some small changes to both the Pi’s and the Arduino’s configuration files. However, the first step is to install the IDE, cross compilers, etc. To use the ISP programming method (which is recommended), you need a modified version of the avrdude program.

First start by installing the standard Arduino IDE. the OS which i used in RPI is RASPBmc.

 

sudo apt-get install arduino

 
This will pull in several packages including the required C compilers and Java based IDE.

Now fetch and install the modified avrdude package:

cd /tmpwget http://blog.bentgeorge.com/uploads/avrdude_5.10-4_armhf.deb

sudo dpkg -i avrdude_5.10-4_armhf.deb
sudo chmod 4755 /usr/bin/avrdude

This will install the modified version of avrdude. The chmod command will let avrdude use the GPIO pins without using sudo. (which is needed to run it inside the IDE)

There are several steps involved,Below procedure automates all the tasks for you.

cd /tmp

wget http://blog.bentgeorge.com/uploads/setup.sh
chmod +x setup.sh
sudo ./setup.sh

Before we can start to program the ATmega, we need to initialise the chip. The chip itself needs to be told about various parameters such as it’s clock speed, how much flash to reserve for the bootloader (none in our case) and so on.

This is known as “programming the fuses”.

The first thing to do is to connect the Breadboard Wired ATMega 328P to your Raspberry Pi and install 4 jumper wires from the Pi’s GPIO to the ATmegas ISP port.Below is a basic connection circuit of ATMega 328P on breadboard.

Arduino_standalone_minimal

Next part is connecting AVR to RPI. here comes the pin-out’s:

GPIO pin 8 -> ISP pin 5 (RESET)
GPIO pin 9 -> ISP pin 1 (MISO)
GPIO pin 10 -> ISP pin 4 (MOSI)
GPIO pin 11 -> ISP pin 3 (SCLK)

please note that we use 5v and GND from Referrer below pin-out while doing cabling:

raspberry-pi-rev2-gpio-pinout

Once that’s done, connect the breadboard to the Pi and power up. Once Linux has booted on the Pi, then run the avrsetup command.

You will be propmpted for the type of ATmega microcontroller; 1 for an ATmega 328p or 2 for the ATmega168.

If this command works OK, you should see the following:

Initialising a new ATmega microcontroller for use with the Gertboard.
 
Make sure there is a new ATmega chip plugged in, and press
.. 1 for an ATmega328p or 2 for an ATmega168: 1
Initialising an ATmega328p ...
Looks all OK - Happy ATmega programming!

 

And that’s it. You can now run-up the ardunio IDE and burn the bootloader. from tools->board->select AVR chip with GPIO and select the programmer “Raspberry Pi GPIO”. Then Run Burn Bootloader option

Share this Story:
  • facebook
  • twitter
  • gplus

About bentech4u

Comments(2)

  1. CS
    1007 days ago

    Nice tutorial! Exactly what I needed to get my Arduino Severino working:) Thanks a lot!

  2. bentech4u
    985 days ago

    Hi CS,

    you are welcome 🙂

Leave a comment