Trouble Programming Atmega328PU on Breadboard with 8MHz internal clock

I have an Atmega328PU which came with pre-burnt 16mHz bootloader breadboarded without crystal or resonator. Vcc = 5V.

I changed the MCU fuses to LO/HI/E = 0xE2/0xDE/0xFE using USBasp and avrdudess to to use 8MHz internal clock. And I can burn the program using avrdudess.

My issue is that I cannot upload the program from the arduino ide.

Arduino IDE board type set to arduino:avr:pro, cpu=8MHzatmega328.

I'm wondering why I get program sync errors when attempting to upload the program via serial to the MCU. Serial monitor is working fine at 9600 baud.

Is it necessary to burn an 8mHz bootloader in this case? If so can some one please give a link to a suitable bootloader please.

oneis: Is it necessary to burn an 8mHz bootloader in this case?

I don't have any experience with avrdudess, but it's likely that when you uploaded to your ATmega328P with the ISP programmer you erased the bootloader, so the bootloader that was on the chip when you bought it is now irrelevant.

This is how you can use your breadboarded chip with the Arduino IDE:

  • Install MiniCore, following the instructions in the readme: url=https://github.com/MCUdude/MiniCore]https://github.com/MCUdude/MiniCore[/url]
  • Tools > Board > ATmega328
  • Tools > Clock > Internal 8 MHz
  • Connect your ISP programmer to the ATmega328P
  • Select the appropriate programmer from the Tools > Programmer menu.
  • Tools > Burn Bootloader
  • Disconnect the ISP programmer from the ATmega328P.
  • Connect the serial adapter between your ATmega328P and computer
  • Select the port of the serial adapter from the Tools > Port menu
  • Sketch > Upload

pert: Thank you for drawing attention to the MiniCore solution. I like the extra features added to the core - printf, etc and the great array of bootloaders.

Great!

Installing MiniCore went OK. But step 6 failed, the bootloader would not burn.

Initially the serial port section was empty until I reinstalled the USBasp driver using Zadig and installed libusb-win32.

Using the same USBasp I can burn hex files and read/write fuses using avrdudess, which provides a gui for avrdude.

Any ideas why the USBasp does not work from the IDE?

IDE Errors:
Arduino: 1.8.5 (Windows 7), Board: “ATmega328, Yes (UART0), 328P / 328PA, BOD 2.7V, LTO disabled, 8 MHz internal”

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Users\Steven\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.0.3/avrdude.conf -v -patmega328p -cusbasp -Pusb -e -Ulock:w:0x3f:m -Uefuse:w:0b11111101:m -Uhfuse:w:0xd6:m -Ulfuse:w:0xe2:m

avrdude: Version 6.3, compiled on Jan 17 2017 at 12:00:53
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch

System wide configuration file is “C:\Users\Steven\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.0.3/avrdude.conf”

Using Port : usb
Using Programmer : usbasp
avrdude: Warning: cannot query manufacturer for device: No such file or directory
avrdude: Warning: cannot query product for device: No such file or directory
avrdude: error: could not find USB device with vid=0x16c0 pid=0x5dc vendor=‘www.fischl.de’ product=‘USBasp’

avrdude done. Thank you.

Error while burning bootloader.

IDE Tools Menu.png

an Atmega328PU which came with pre-burnt 16mHz bootloader breadboarded without crystal or resonator.

A confusing statement. Are you saying it was pre-burned at 16MHz without using an external resonator, and if so how do you know that? Or are you saying it was pre-burned at 16MHz using an external resonator but you don't have an external resonator?

In my experience, and I'm not an expert, if it was pre-burned with an external resonator, you need an external resonator to burn a different bootloader. So try buying a 16MHz crystal and associated pair of caps (can't remember appropriate values) and connect those on the breadboard before trying to burn the bootloader again.

PaulRB: Sorry for confusing statement. The Atmega328PU was purchased with a bootloader pre-burnt.

I wanted to make the point that I have programmed the MCU fuses to use the internal 8mHz clock but the MCU bootloader is still the 'standard' one as purchased which I assume is for 16mHz use.

There are two issues when using the IDE:

  • I get sync errors on uploading the program
  • I get the above errors when trying to burn the bootloader.

If I remember well , I had same problem in the past. It needs the external 16Mhz resonator to burn the bootloader.

PaulRB: In my experience, and I'm not an expert, if it was pre-burned with an external resonator, you need an external resonator to burn a different bootloader. So try buying a 16MHz crystal and associated paid of caps (can't remember appropriate values) and connect those on the breadboard before trying to burn the bootloader again.

AlessioDuchi: If I remember well , I had same problem in the past. It needs the external 16Mhz resonator to burn the bootloader.

Right on the money. If the fuses on the microcontroller are set to use an external clock source then you're going to need to provide one before you can reprogram it.

BJHenry: If the fuses on the microcontroller are set to use an external clock source then you're going to need to provide one before you can reprogram it.

But the OP has changed those fuses so it should accept internal clock source. They did this using AVRDudess, which I've never used, so I can't advise what could be wrong.

All I know is that I have accidentally burned bootloader with the clock source accidentally set to 16MHz external. The only way I found to recover the chip was to connect a 16MHz crystal.

I think the lesson here is, if you are buying a chip to replace a fried chip on an Uno R3, buy one with the 16MHz external clock & bootloader installed. But if you have the knowledge and equipment to burn bootloaders yourself, buy the "blank" chips with the default 1MHz internal clock setting and no bootloader.

This is about internal 8mHz clock, not external. The fuses are definitely set to internal so any attached crystal or resonator will be ignored.

I have uploaded a sketch with avrdudess, running the sketch the delay(n ms) is correct, ie delay(1000) gives a true 1 second delay. I assume from this that the 8mHz bootloader that I have also programmed using avrdudess has got into the MCU correctly.

It's more convenient to use the IDE for uploading sketches. As far as I can see the IDE employs avrdude to program and change fuses etc, avrdudess is only a graphic interface for avrdude.

When I have time I will analyse the command lines sent to avrdude by the IDE and those used by avrdudess.

One thing that would be useful is to know is how the hex file address maps to the sketch, bootloader and likewise for the fuses and baud rate (I mean the baud rate that the MCU expects from the serial programmer).

Thanks for the various inputs, when I find out what's going on I'll post back.

PaulRB:
But the OP has changed those fuses so it should accept internal clock source. They did this using AVRDudess, which I’ve never used, so I can’t advise what could be wrong.

Sorry, I had missed that.

oneis:
avrdude: Warning: cannot query manufacturer for device: No such file or directory
avrdude: Warning: cannot query product for device: No such file or directory
avrdude: error: could not find USB device with vid=0x16c0 pid=0x5dc vendor=‘www.fischl.de’ product=‘USBasp’

avrdude done. Thank you.

Error while burning bootloader.

Op, if this is the current issue then you might be having trouble with the drivers themselves. I can’t explain why AVRDudess would be working while the Arduino IDE isn’t, but this thread covers the same problem.

BJHenry: As previously stated there was a driver issue because the IDE Tools serial port section was empty until I reinstalled the USBasp driver using Zadig and installed libusb-win32, after which the serial port appeared correctly. Also the Serial.print function works fine. Maybe the serial upload baudrate is not matching between IDE and the board. Also seperately the IDE will not burn the bootloader.

Edit: Just used Zadig to update the USB driver to libusbK instead of libusb-win32, unfortunately it didn't help.

oneis: BJHenry: As previously stated there was a driver issue because the IDE Tools serial port section was empty until I reinstalled the USBasp driver using Zadig and installed libusb-win32, after which the serial port appeared correctly. Also the Serial.print function works fine. Maybe the serial upload baudrate is not matching between IDE and the board. Also seperately the IDE will not burn the bootloader.

The USBAsp doesn't function as a USB-Serial adapter, it won't show up in the Tools>Serial Port selection menu.

The USBAsp doesn't function as a USB-Serial adapter, it won't show up in the Tools>Serial Port selection menu.

Ahh, thanks for that. This was in relation to burning the bootloader in the IDE with programmer set to USBAsp as per pert's suggestion to use MiniCore. On step 9 I thought I should see both the CP2104 serial adaptor and the USBAsp. Actually the USBAsp port did show up after reinstalling the libusb-win32 driver, it showed as COM1 without a description.

This raises a question: can the IDE burn a bootloader with either a serial connection or a programmer like USBAsp that uses the SPI bus?

Can someone explain what magic Avrdudess uses to write fuse bits on a chip that has fuse bits set for external crystal with no crystal.?

I can't even read fuse status on a chip missing the crystal using a USBasp .

oneis: can the IDE burn a bootloader with ... a serial connection

No.

You can use USBAsp, or another Arduino with the ArduinoISP sketch loaded (plus anti-reset cap).

kprims: Can someone explain what magic Avrdudess uses to write fuse bits on a chip that has fuse bits set for external crystal with no crystal.?

I can't even read fuse status on a chip missing the crystal using a USBasp .

USBasp uses SPI (MOSI,MISO,CLK) to communicate program instructions and data transfer to the MCU so it shouldn't care what crystal is fitted or what fuses are set. If you can't read the fuses it probably means the USBasp programmer is not communicating. What do you have the Avrdudess programmer set to? And what reason/error is it showing?

When I do exactly what you are doing with my Avrdudess programmer set to 'USBasp. http://www.fischl.de/usbasp' the result of a read is:

Reading fuses... SUCCESS: Read low fuse SUCCESS: Read high fuse SUCCESS: Read extended fuse

PaulRB: No.

You can use USBAsp, or another Arduino with the ArduinoISP sketch loaded (plus anti-reset cap).

Yes that makes sense, slowly the jigsaw picture comes into view!

"USBasp uses SPI (MOSI,MISO,CLK) to communicate program instructions and data transfer to the MCU so it shouldn't care what crystal is fitted or what fuses are set."

I have to disagree here. This may be a learning experience for me. In my experience a chip that has the fuses set for external crystal needs a crystal or a separate clock lead in order to program using SPI (USBasp .

So , what value does Avrdudess show for your fuses?

Reading fuses... SUCCESS: Read low fuse SUCCESS: Read high fuse SUCCESS: Read extended fuse

Reading atmega328p with 16 mHZ crystal .

avrdude -v -patmega328p -cusbasp 

avrdude: Version 6.3
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "/home/kprims/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb
         Using Programmer              : usbasp
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : usbasp
         Description     : USBasp, http://www.fischl.de/usbasp/

avrdude: auto set sck period (because given equals null)
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: safemode: hfuse reads as DE
avrdude: safemode: efuse reads as FD

avrdude: safemode: hfuse reads as DE
avrdude: safemode: efuse reads as FD
avrdude: safemode: Fuses OK (E:FD, H:DE, L:FF)

avrdude done.  Thank you.

Reading same chip with no crystal.

$ avrdude -v -patmega328p -cusbasp 

avrdude: Version 6.3
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "/home/kprims/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb
         Using Programmer              : usbasp
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : usbasp
         Description     : USBasp, http://www.fischl.de/usbasp/

avrdude: auto set sck period (because given equals null)
avrdude: error: program enable: target doesn't answer. 1 
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.


avrdude done.  Thank you.

I have to disagree here. This may be a learning experience for me. In my experience a chip that has the fuses set for external crystal needs a crystal or a separate clock lead in order to program using SPI (USBasp .

Do the above statement refer to using the IDE or avrdudess? So far my experience programming the bootloader is limited to avrdudess because I can't get the IDE to burn a bootloader - yet.

My limited experience is that avrdudess burns the flags and bootloader irrespective of either 16mHz (external) crystal or internal 8mHz clock using USBasp. But using the exact same hardware the IDE does not.

So , what value does Avrdudess show for your fuses?

Currently the fuses are set to: LO/HI/E = 0xE2/0xDE/0xFE (internal 8mHz clock & BOD = 2.7v)