ATMEGA328p uploading a sketch

Hi,

I'm trying to create a PCB project using a atmega328p TQFP. The boards arrived today assembled so I began testing them. I managed to burn the bootloader with no issues using a Nano (with the capacitor over reset). My issue arises when I try to upload a sketch.

To do this I'm using this method. I know it works as I can upload the same sketch to a standalone atemga328p DIP on a breadboard and that works fine. When I try to upload to my PCB I get the following message.

Sketch uses 450 bytes (1%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
/private/var/folders/94/f3hz7ssd1z57fv4jg6cnhy480000gn/T/AppTranslocation/F3B5B965-40B8-4010-8AD0-6A2ECCD3A6E6/d/Arduino-2.app/Contents/Java/hardware/tools/avr/bin/avrdude -C/Users/james/Library/Arduino15/packages/MiniCore/hardware/avr/2.0.3/avrdude.conf -v -patmega328p -carduino -P/dev/cu.usbmodemFA141 -b38400 -D -Uflash:w:/var/folders/94/f3hz7ssd1z57fv4jg6cnhy480000gn/T/arduino_build_501837/sketch_oct26b.ino.hex:i 

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/james/Library/Arduino15/packages/MiniCore/hardware/avr/2.0.3/avrdude.conf"
         User configuration file is "/Users/james/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/cu.usbmodemFA141
         Using Programmer              : arduino
         Overriding Baud Rate          : 38400
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00

avrdude done.  Thank you.

Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

I know the reset, Vcc & Gnd connections to the PCB work as they are required for the boot loader. Ive checked with a multimeter that the TX & Rx connections are going to the correct pins and they are. I've also tried the manual reset using a jumper wire just prior to uploading the sketch in absence of a reset button, but to no avail.

After the message above the LED connected to pin D13 on the atmega328p flashes twice, small delay and keeps repeating. All the ports and settings are correct as I can upload to a standalone DIP but not to the PCB. I really am drawing a blank on this one, if anyone had any suggestions or things to check I would be very grateful.

Thanks.

Circuit Diagram. I noticed that the buzzer would cause the serial connection to fail, so I’ve left the buzzer unsoldered. There is a direct connection from Rx to Tx and vise versa. The diode connected to the other serial connection Ive tested on a DIP 328p and had no effect, just to be safe I unsoldered that too. I’ve played around with different capacitor values or tried removing them just to see if i could emulate the error message on the DIP and i cant, so I am thinking that the Xtal is working correctly. It just doesn’t want to communicate.

OP's schematic:

First off, your thread title says you're using an ATMega328P, but your schematic shows an ATMega328PB. Are you aware of the different? Do you have Minicore so that you're able to use the 328PB easily and without messing around with variant board files?

Secondly, the resolution on that schematic isn't really good enough to see some details. Is the crystal 8MHz or 16MHz?

Thirdly, you appear to be missing the 100nF decoupling capacitors for each of the VCC/AVCC pins. These are vital and until you have them on the board there's not much point testing for any other problem since the behaviour of the micro will be unreliable.

Fourthly, the reset circuit is missing the required capacitor to let your USB-Serial adapter reset the micro correctly.

Thanks for your response.

Im just using arduino IDE, burning an 8Mhz external bootloader to it. and uploading the sketch via a Uno with the chip removed. This works fine for the DIP.

Yes I am aware of that, I was being a bit sloppy and rather than change the chip out for a atmega328p in EasyEDA, I just rewired it as per what I wanted then changed the Manufacturing number on the specs so a -p came assembled, and not a -pb. I ve checked the Vcc and Gnd pins and they are wired correctly.

Im using an 8Mhz Xtal with 22pf capacitors. I've tried removing the Xtal on my atmega328p DIP setup and didn't get the same error messages so I don't think its capacitor related.

The error I get when attempting to upload a sketch is the same as if the USB is not even plugged in...

I had a 10uf capacitor across the power rails which I thought would be sufficient. In my tests on the DIP I had no capacitors at all, on Vcc or across reset and I am still able to upload to that just fine.

However, I removed the 10uf cap, and replaced with 100nF caps on both the Vcc in pins. Ive also added the aforementioned cap across reset. Unfortunately still no joy. Same error as before. And I am still able to burn the boot loader to it no problem. TIA.

So I think I may have made a small bit of progress. I have found some interesting behaviour that I cannot explain.

As I could upload the boot loader but not a sketch I was thinking the issue may lie with the Tx and Rx connections. I made a simple buzzer circuit, with two wires open circuited. This acted as a little tester, I placed one wire on one part of the PCB and the other wire on another part and see if I could hear the buzzer..

I tested the GND and Vcc terminals and everything was as expected. But I got something strange when I tested Tx & Rx. If either one is tested, the other wire can be placed on Vcc/Gnd/Tx or Rx/PB3/PB4/PB5 and you can hear the buzzer. So it seems that Tx and Rx are somehow short-circuited to everything else.

Now Tx to Gnd I can understand as theres a diode and resistor to ground. but Rx to Gnd? The piezo in the circuit has yet to be soldered so there is no direct connection to anywhere else.

And Gnd to Vcc doesn't make any sense unless the capacitor is facilitating that.

arduino IDE, burning an 8Mhz external bootloader to it. and uploading the sketch via a Uno with the chip removed. This works fine for the DIP.

You mentioned DIP....if you’re using SMT, Have you checked the pin numbers you’re using? Usually different.

Yup checked all the pin outs, I was using a DIP on a breadboard just for testing prior to the SMD version.

Ive made a revised PCB, if anyone has any comments/tips about this one Im all ears. My only concern is that the differences I made to this new design I modified my last one to include these, like the extra caps ect. and it still didnt upload.

Are there any other rules that one should follow like track length for certain frequency pins like Rx Tx? Some of my routings were a bit long and convoluted, not sure if that had a part to play. Thanks.

Schematic_Audible AltiNew XTAL V2_Sheet_1 copy copy_20191028213332.pdf (81.6 KB)

if you’ve got bypass caps, good voltage and ground on the pins it should be enough. The LED flickering suggests a bootloader is waiting, so if your serial connections (including DTR-cap-reset) are right, it should be a go-er...