ArduinoISP Programming Problem

I'm somewhat new to Arduino Programming and the AtMega328 device.

Having had some success with the Uno R3 I wanted to use the AtMega328 as a standalone controller in future projects.

I bought an ArduinoISP (A000092) and installed the correct drivers to recognise the ArduinoISP USB Device.

I put a blank ATMega328 device (completely new without bootloader) into the DIP socket on the Uno R3 Board and connected the ArduinoISP to the Uno and the ArduinoISP to my PC.

In Aduino IDE (V. 1.7.9 ) I selected ArduinoISP.org as the programmer and Uno as the board.

I loaded the Blink sketch and then tried to download it to the blank ATMega328 on the Uno board using the "Upload Using Programmer" option in the IDE.

The upload seemed to work with no errors shown. However the program did not run. I pressed Reset on the Uno board and still no luck.

After a bit of headscratching I used the "Burn Bootloader" option on the Arduino IDE, still using the ArduinoISP as the programmer.

This worked without any problem. Once this was done the Blink program ran correctly.

I was under the impression that the Bootloader wasn't necessary in order to run programs if the programs were loaded via an ISP.

My suspicion is that something is missing in a blank 328 chip and that this is installed with the bootloader. I'm guessing that this might be fuses for oscillator selection or similar - or it might be that the bootloader specifies a particular location to load the sketch.

Does anybody have an explanation for why the addition of the bootloader would make the Sketch run?

I'm used to Microchip PICs but love the simplicity of the Arduino programming interface and the availability of the Arduino forums to get help.

Regards

PJW863123

PJW863123: I loaded the Blink sketch and then tried to download it to the blank ATMega328 ... However the program did not run.

Did you wait the requisite 16 seconds between blinks?

“Did you wait the requisite 16 seconds between blinks?”

Not sure what you mean here - am I missing something?

PJW863123

Factory '328p runs at 1mhz off the internal oscillator (8mhz divided by 8, per CKDIV8). If you upload a sketch to it compiled assuming it's running at 16mhz, the sketch will run 16 times slower.

When you do burn bootloader, that also sets the fuse bytes, which tell it what clock source to use and whether to divide it by 8 (among other things)

DrAzzy Thank you for that.

I'm not sure that I would have waited the 16 seconds that was suggested......

Is there a way of setting the fuses using the ArduinoISP and Arduino IDE or do I have to look at other options?

Regards

PJW863123

Yes. Tools / Burn Bootloader changes the fuses (reread reply #3). avrdude, a command-line tool, can be used to read / write the fuses. There are at least two interactive tools available for manipulating the fuses.

With a USBAsp there's even the GUI tool.

Burn bootloader is fine though - after burning bootloader, you can erase the bootloader by uploading any sketch over ISP (ie, using Upload using Programmer). When programming by ISP, it can only erase all the flash at once (not one page at a time like you can do with bootloader).

You need to Burn Bootloader in the IDE to get the fuses set up. After that, Arduino ISP just uploads the sketch and fuses are left alone. I've done the latter without doing the former many times and then spent a half hour wondering why things seemed to be running so slow until I remembered!