Instructables

Step 9: Flash the bootloader

This step will burn the boot loader to the chip. You will need an Arduino with ArduinoISP loaded on it. If you have another programmer, I assume you know how to use it.

Wiring from the existing Arduino
The picture shows a Pro-Mini, but any Arduino compatible should work.
  1. Load ArduinoISP to your existing (or borrowed) Arduino.
  2. Connect D9 to a resistor (220ohm-1k works with most leds) and a LED so you can see the "heartbeat".
  3. Optionally connect  D7 and D8 so you can see what's going on. I don't normally use them when things are working.
  4. Connect VCC and GND between the boards.
  5. Connect D10 on the programmer to RST on your new board.
  6. Connect D11 to D11
  7. Connect D12 to D12
  8. Connect D13 to D13
Connect the computer to the Arduino via the USB cable and determine the USB port. Mine was com16 so all my examples use that. Change to fit your situation.

On the computer

Prepare your software

  1. Open the Arduino IDE
  2. Load the ArduinoISP sketch
  3. Double check the Serial.begin command is set to 19200.
  4. Load it onto your Arduino and make a note of the serial port you used. You will need to use it below with AVRDude.
  5. Check the heartbeat is working. If it ever stops when AVRDude isn't running, hit the reset button.
  6. Install or locate WinAVR.
  7. Download Optiboot.hex and put it in the WinAVR bin directory
Check the connections
  1. Open a command prompt. (Start->cmd.exe)
  2. Use the CD command to change to the WinAVR bin directory. (remove quotes) "CD C:\winavr\bin" for example.
  3. Run the following command (remove quotes and use your own com port)

"avrdude -p m328p -P com16 -c avrisp -b 19200"

If all is well, you will see a chip signature of "0x1e9514" even though AVRDude says "Yikes I was expecting 0x1e951...". Skip down past troubleshooting and burn the bootloader. If you see 0x000000 or another error, do the troubleshooting.


Troubleshooting
  • Hit the reset button on the Arduino,  briefly ground RST on your new board and try again.
  • Triple check your wiring. Did you get GND and VCC right?
  • Double check your com port.
  • Check the board again for defects. Use a meter to check RST, and D11-13.
  • Remove all the wiring and do it over.
  • Take a break, think for a while, look at the setup with fresh eyes.
  • Show it to a helper and explain things. Even (especially?) if they don't care you will notice errors this way often.
  • Look for help with AVRDude online, and post here with photos of your setup.
Burn the bootloader
Make a file called ard328burn.cmd in the WinAVR bin directory and copy this text into the file. Change com16 if you use another port.

Code (Don't include this line)

@echo off
avrdude -p m328p -P com16 -c avrisp -b 19200
echo enter to continue, CTRL-C to exit. Hit enter if you see 0x1e9514
pause
avrdude -p m328p -P com16 -c avrisp -b 19200 -F –e
echo hit enter if there were no errors. CTRL-C to exit.
pause
avrdude -p m328p -P com16 -c avrisp -b 19200 -F -U lock:w:0x3F:m
echo hit enter if there were no errors. CTRL-C to exit.
pause
avrdude -p m328p -P com16 -c avrisp -b 19200 -F -U lfuse:w:0xFF:m -U hfuse:w:0xDE:m efuse:w:0x05:m -U flash:w:optiboot_atmega328.hex -U lock:w:0x0f:m

EndCode (Don't include this line)

Type "ard328burn.cmd" and the burning should start. The first message will complain about the Signature, but that's expected. Hit enter if the signature is 0x1e9514. If it's 0x000000 something is wrong. Often this means you mixed up 11,12 and/or 13s wires. Watch each step and hit Enter if there are no errors.

Check the bootloader.
If all is well, the on board LED is blinking on and off. If not, try resetting the board. Connect RST to GND for a moment and see if the on board LED flashes and starts blinking. If the LED on the existing Arduino is flashing and yours isn't it means the only thing wrong is your LED. Maybe you got it backwards or it (or it's resistor) isn't connected. I had to touch one up with a solder iron when I got the resistor upside down on accident.

If this doesn't work, reset the Arduino and your board. Then run the batch file again. Examine the output carefully to be sure everything went well. AVRDude will read the data back and double check that it is correct.

Now you can plug in your new Arduino Compatible with the FTDI breakout. Set the Arduino IDE to "Uno" and flash a program onto the chip.

djmanning2 years ago
I tried using an Uno with the following sketch loaded:

https://github.com/WestfW/OptiLoader

connect d11-13, d10->RST, GND, 5v -> VCC as explained in the instructable.

It worked first time. No need for avrdude. I just tested the blink sketch on my soldered Extracore and it's happily blinking away.

Cheers,

Don
dustinandrews (author)  djmanning2 years ago
Glad to hear it works!
djmanning2 years ago
I've checked my solder joints and make it through all the steps in programming using a Nano 2.3 as my arduino helper. instead of 0x1e9514, i get 0x1e950f. All programming steps complete without errors. When I move over to programming, the board doesn't respond and no flashing LED. check connections but I'm stuck. Anyone else seen 0x1e950f and know what it might be pointing toward?
Thanks,
dustinandrews (author)  djmanning2 years ago
0x1e950f is the m328p atmega chip. It's not exactly the same one I used, but it's supported out of the box by WinAVR and should be virtually identical (I think it's just differs in some low voltage features).

In the last command Avrdude should spend some time reading the program back out of the chip. Is that successful?

Are you using an FTDI chip or cable? Hook it up and check for +5v on both of the VCC pins.

Try putting your chip in a breadboard and powering it with +5v and briefly ground the reset pin. The LED should flash as the chip boots up.

You can also try the stock Arduino bootloader. The Ardunio IDE should be able to flash the chip since it has a 0x1e950f signature.

Failing that, can you describe where you got your board and how you made it? Maybe post some photos of your connections?
That's strange. I was part of the Kickstarter group and got 5 kits. This was the first build of the 5 kits. The chip definitely has m328p stamped on it. I also have a Ruggedcircuits built Extracore that works fine and has m328p also stamped on it. I have the output of all the programming in a text file if you're interested.
Attached is an image of the soldered board. I followed the instructable for soldering and connecting the board to my Nano to load the bootloader. I soldered headers for only the minimum needed to program the board.

I do have an FTDI TTL-232R-3v3 that I've used to program other Arduinos, mostly pro minis. I attached it to the Ruggedcircuits one and loaded a basic sketch without issue. Is there a way to program the bootloader using FTDI cable and not use the Nano? I don't think so but I thought I would ask.

I can hook back up the Nano to the Extracore and shoot that picture if needed but the programming output might be more help. I couldn't get a good picture with all the connections between the EC and the Nano.

Is there a forum or support email that I'm missing? Let me know if this is the best place to post questions.

Cheers,

Don
IMG_0794.JPG
dustinandrews (author)  djmanning2 years ago
You probably just need to supply 5v to VCC. Be sure to disconnect the 5v pin to the FTDI so you don't overload it.

This is a great place for questions.

You could hack the fuses to run the chip at 8mhz and then 3.3v should work, but that's untested and unsupported. I have bricked chips messing up fuses.
I posted the results of programming the bootloader here: http://shorttext.com/oDay0CX

Cheers,

Don