[Solved]Cannot upload sketch to Atmega328p TQFP soldered on PCB

After creating a working prototype with DIP Atmega328 chip/ arduino uno I recently got PCBs assembled with SMD components and Atmega328p TQFP soldered onto them, but now I'm having a hard time trying to upload the arduino program.

This is the schematic of the PCB with Atmega328p TQFP with ISP headers for programming: |500x313

I'm using usbasp programmer with upgraded firmware to upload the code. The chip gets detected and also I can upload sketches to it but the problem is the code runs slow, which I found out is due to the default 8MHz internal clock.(the blink program makes LED blink every 16 seconds instead of 1 second,i.e. with delay(1000))

Now to switch to the external 16MHz clock which I want to use I found out [here][2] that I have to change the fuse values from the default

lfuse: 0x62 hfuse: 0xD9 efuse: 0x3F

to

lfuse: 0xFF hfuse: 0xDE efuse: 0x05

I tried it two times and both the times it screwed up the Atmega328p chip

C:\Users\p>avrdude -p m328p -c usbasp -U lfuse:w:0xFF:m -U hfuse:w:0xDE:m -U efu
    se:w:0x05:m
    
    avrdude: AVR device initialized and ready to accept instructions
    
    Reading | ################################################## | 100% 0.03s
    
    avrdude: Device signature = 0x1e950f
    avrdude: reading input file "0xFF"
    avrdude: writing lfuse (1 bytes):
    
    Writing | ################################################## | 100% 0.02s
    
    avrdude: 1 bytes of lfuse written
    avrdude: verifying lfuse memory against 0xFF:
    avrdude: load data lfuse data from input file 0xFF:
    avrdude: input file 0xFF contains 1 bytes
    avrdude: reading on-chip lfuse data:
    
    Reading | ################################################## | 100% 0.01s
    
    avrdude: verifying ...
    avrdude: 1 bytes of lfuse verified
    avrdude: reading input file "0xDE"
    avrdude: writing hfuse (1 bytes):
    
    Writing | ################################################## | 100% 0.03s
    
    avrdude: 1 bytes of hfuse written
    avrdude: verifying hfuse memory against 0xDE:
    avrdude: load data hfuse data from input file 0xDE:
    avrdude: input file 0xDE contains 1 bytes
    avrdude: reading on-chip hfuse data:
    
    Reading | ################################################## | 100% 0.01s
    
    avrdude: verifying ...
    avrdude: 1 bytes of hfuse verified
    avrdude: reading input file "0x05"
    avrdude: writing efuse (1 bytes):
    
    Writing | ################################################## | 100% 0.03s
    
    avrdude: 1 bytes of efuse written
    avrdude: verifying efuse memory against 0x05:
    avrdude: load data efuse data from input file 0x05:
    avrdude: input file 0x05 contains 1 bytes
    avrdude: reading on-chip efuse data:
    
    Reading | ################################################## | 100% 0.01s
    
    avrdude: verifying ...
    avrdude: 1 bytes of efuse verified
    
    avrdude: safemode: Fuses OK
    
    avrdude done.  Thank you.
    
    
    C:\Users\p>avrdude -p m328p -c usbasp
    
    avrdude: error: programm 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.

Both of the PCBs are not responding to the usbasp programmer and now I have only got one PCB left. I desperately want to get the final one working.

This is my first time using the SMD Atmega328p chips and any help would be appreciated.

prithvee:
After creating a working prototype with DIP Atmega328 chip/ arduino uno I recently got PCBs assembled with SMD components and Atmega328p TQFP soldered onto them, but now I’m having a hard time trying to upload the arduino program.

This is the schematic of the PCB with Atmega328p TQFP with ISP headers for programming:

Is the Schematic Accurate?

Do you Really have 100nf capacitors on the X1,X2?

I am very surprised the Crystal can actually oscillate.

The Arduino Reference design uses 22pf, not 100000pf caps on the oscillator circuit.

Arduino Uno rev 3 Reference Schematic

I have had good luck with resonators that include the caps.

My 328p circuit.

Chuck.

prithvee:
After creating a working prototype with DIP Atmega328 chip/ arduino uno I recently got PCBs assembled with SMD components and Atmega328p TQFP soldered onto them, but now I’m having a hard time trying to upload the arduino program.

I’m using usbasp programmer with upgraded firmware to upload the code. The chip gets detected and also I can upload sketches to it but the problem is the code runs slow, which I found out is due to the default 8MHz internal clock.(the blink program makes LED blink every 16 seconds instead of 1 second,i.e. with delay(1000))

Now to switch to the external 16MHz clock which I want to use I found out [here][2] that I have to change the fuse values from the default

to

I tried it two times and both the times it screwed up the Atmega328p chip

C:\Users\p>avrdude -p m328p -c usbasp -U lfuse:w:0xFF:m -U hfuse:w:0xDE:m -U efu

se:w:0x05:m
   
   avrdude: AVR device initialized and ready to accept instructions
   
   Reading | ################################################## | 100% 0.03s
   
   avrdude: Device signature = 0x1e950f
   avrdude: reading input file “0xFF”
   avrdude: writing lfuse (1 bytes):
   
   Writing | ################################################## | 100% 0.02s
   
   avrdude: 1 bytes of lfuse written
   avrdude: verifying lfuse memory against 0xFF:
   avrdude: load data lfuse data from input file 0xFF:
   avrdude: input file 0xFF contains 1 bytes
   avrdude: reading on-chip lfuse data:
   
   Reading | ################################################## | 100% 0.01s
   
   avrdude: verifying …
   avrdude: 1 bytes of lfuse verified
   avrdude: reading input file “0xDE”
   avrdude: writing hfuse (1 bytes):
   
   Writing | ################################################## | 100% 0.03s
   
   avrdude: 1 bytes of hfuse written
   avrdude: verifying hfuse memory against 0xDE:
   avrdude: load data hfuse data from input file 0xDE:
   avrdude: input file 0xDE contains 1 bytes
   avrdude: reading on-chip hfuse data:
   
   Reading | ################################################## | 100% 0.01s
   
   avrdude: verifying …
   avrdude: 1 bytes of hfuse verified
   avrdude: reading input file “0x05”
   avrdude: writing efuse (1 bytes):
   
   Writing | ################################################## | 100% 0.03s
   
   avrdude: 1 bytes of efuse written
   avrdude: verifying efuse memory against 0x05:
   avrdude: load data efuse data from input file 0x05:
   avrdude: input file 0x05 contains 1 bytes
   avrdude: reading on-chip efuse data:
   
   Reading | ################################################## | 100% 0.01s
   
   avrdude: verifying …
   avrdude: 1 bytes of efuse verified
   
   avrdude: safemode: Fuses OK
   
   avrdude done.  Thank you.
   
   
   C:\Users\p>avrdude -p m328p -c usbasp
   
   avrdude: error: programm 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.



Both of the PCBs are not responding to the usbasp programmer and now I have only got one PCB left. I desperately want to get the final one working.

This is my first time using the SMD Atmega328p chips and any help would be appreciated.

I think when you select the external Oscillator with the fuses, and the Oscillator circuit doesn’t work. that is what bricks your board. Change C5, C6 to 22pf 0.000022uf.

You might also have to add a 1M resistor across the Crystal (x1,x2) to support the oscillator.

Just changing the capacitors might be enough though, the AVR is pretty tough.

After the fuse setting change, the AVR is using the External Crystal circuit, with is not working that is why your ISP programmer can’t ID the AVR.

Do you have an oscilloscope? If you do, check the Xtal1 pin for a sine wave at 16mhz. if All you have is a DC voltage. (which is what I expect you have) That identifies the problem.

Chuck.

chucktodd: Do you have an oscilloscope? If you do, check the Xtal1 pin for a sine wave at 16mhz. if All you have is a DC voltage. (which is what I expect you have) That identifies the problem.

Check on Xtal2 - PB7 - not Xtal1 which is the oscillator input.

chucktodd:
Is the Schematic Accurate?

Do you Really have 100nf capacitors on the X1,X2?

I am very surprised the Crystal can actually oscillate.

The Arduino Reference design uses 22pf, not 100000pf caps on the oscillator circuit.

Arduino Uno rev 3 Reference Schematic

I have had good luck with resonators that include the caps.

My 328p circuit.

Chuck.

Thank you, it works after replacing the caps with 22pF ones!

prithvee: Thank you, it works after replacing the caps with 22pF ones!

Yea!

Chuck.

prithvee: Thank you, it works after replacing the caps with 22pF ones!

As it would! :roll_eyes: