Programming a new ATMEGA328P works but oscillator does not start

I have developed a board with an ATMEGA328P on it and I am planning to run it as a classic Arduino Nano (a nano embedded in my own board). I have used an Arduino Uno to program the bootloader on it, but the external 16MHz oscillator does not seem to start when I check it with an oscilloscope.

The programming of the bootloader went fine (it writes and reads back everything):

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

         System wide configuration file is "/Users/rolf/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf"
         User configuration file is "/Users/rolf/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/cu.usbmodem101
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega328P
...
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.02s
avrdude: Device signature = 0x1e950f (probably m328p)
...
avrdude: writing flash (32768 bytes):
Writing | ################################################## | 100% 0.00s
avrdude: 32768 bytes of flash written
...
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 0.00s
avrdude: verifying ...
avrdude: 32768 bytes of flash verified
...
avrdude: reading on-chip lock data:
Reading | ################################################## | 100% 0.01s
avrdude: verifying ...
avrdude: 1 bytes of lock verified
avrdude done.  Thank you.

I don't see any errors or warnings in the process above. (dots are snips, if I need to post more logging let me know).

Then when I connect my homebrew board (with ftdi chip) to my USB port, the computer (MacOS) recognizes that there is a USB device connected. When I try to get the board info it complains that it doesn't know what board it is (I can accept that).

When I try to flash a program to the board it seems to send data to the board, but then the log shows:

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

         System wide configuration file is "/Users/rolf/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf"
         User configuration file is "/Users/rolf/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/cu.usbserial-A50285BI
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00

Since the oscilator does not seem to be running, I suspect that I have one of the following problems:

  1. The fuses aren't set correctly (although the avrdude logging above seems to indicate that it is setting fuses, and since I replicated the Nano schematic, I assumed that it would set the fuses to use the external oscillator.
  2. The oscillator itself is not the correct make/model and the atmega can't get it to oscillate

I am wondering what the next smart step is in analyzing this problem, before ripping off the oscilllator and replacing it with one off of an original Arduino Nano board.

Please post a complete schematic diagram, and a close up, focused photo of the board.

Of course, sorry for being incomplete. The schematic:

A photo of the processor part of the board:

Please note that on the schematic I was missing the 22pF capacitors (doh!) and I had to add them later, so it doesn't look all that great. The next revision of the board will get the capacitors, but not before I figure out why the oscillator doesn't start.

I have verified that the pins aren't shorted, and the 16MHz resonator that is hidden underneath the capacitors is a 16.000Mhz 5032 Smd Quartz Resonator like this one:

If someone can confirm that the bootloader burning process is indeed setting the fuses correclty for the external 16MHz resonator, I think I need to re-do that circuit (first the experimantal way of course :wink: )

I doubt that the fuses are set correctly, but I don't use that method of programming (I use a commercial programmer with Atmel/Microchip Studio). You need to read out all the fuses and check them.

If they were not set correctly, the chip will still be running on the internal 8 MHz RC oscillator, with the CKDIV8 fuse set, for 1 MHz clock frequency.

There are instructions somewhere on line for reading/writing fuses, using the setup you have.

Thanks jremmington, I found avrdude inside the Arduino IDE folder and found out how it is used when programming using an Arduino as ISP. I was able to read the flags:

./bin/avrdude \
        -C./etc/avrdude.conf \
        -v -patmega328p \
        -cstk500v1 \
        -P/dev/cu.usbmodem101 \
        -b19200 -U lfuse:r:-:i -v

The output shows that the Arduino IDE does set the flags correctly when burning the bootloader:

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

This should enable the 328p to use the external 16MHz chrystal oscillator. In my case it does not start, so I am now planning to replace that oscillator with another model.

If the oscillator wasn't starting, you wouldn't be able to read the fuses.
This is the number one way to "brick" an AVR chip - the clock is needed for ISP programming, so if you set the fuses to a value so that the clock requires a crystal that isn't there, the chip appears to go completely dead. (it can be revived by injecting a clock.)

The 1k pull up resistor on the reset pin looks rather strong. Usual is 10k.

If it still does not allow you to upload code via the FTDI circuit, verify the connections. Maybe also add a led to pin D13 (SCK broken out on the ICSP header) to see some bootloader activity.
One classic error is overwriting the bootloader by attempting to upload a sketch with the the ICSP programmer still attached.

Interesting. So the fuses are set for external clock but when I use an oscilloscope to check the clock it is not oscillating. Judging above answers, it should either be oscillating, but the probe capacitor makes it stop, or it is using the internal oscillator.
I will check the FTDI connections first, maybe scrape off some soldermask to put some LED's on the lines to check for activity during upload. I'll report back here as soon as I've done that. Thanks for all the help so far!

An other way to check is to use "upload using programmer" which will load a sketch the same way as "burn bootloader" (ICSP via your Uno); this will not change the fuses. If you use the blink example, the LED should blink as expected.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.