Uploading sketch to atmega328P

Hey everyone!
First, let me say that I'm not 100% sure this is the correct place for this question, and if it is not, I apologize.

I've designed a PCB with an ATMega328P, SMD LEDs and Resistors, a 3V CR2032, Power Switch, and 16Mhz resonator. I've soldered everything in its place and burned the bootloader to the board using an Adafruit Boarduino as an ISP targeting a LilyPad arduino. When doing this, one of the LEDs, connected to one of the programming pins, flashes a bunch of times, then I get the message in the Arduino IDE saying that everything is okay.

Now, I'm trying to upload a sketch to the board using the FTDI cable connected to my breadboard with jumper wires, and pogo pins to make contact with the board itself, like this:

FTDI------POGO PINS/ATMEGA328P

  • v+
    rx rx
    tx tx
    reset reset

When I try uploading the sketch, I get errors

avrdude: stk500_getsync(): not in sync: resp=0x00
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51

I've checked around and can't find any information that could solve the issue and I'm not sure what else to try.

FTDI TX goes to ATmega RX and vice versa.

Did do you put a 100nF capacitor on the ATmega328 RESET and connect that to the DTR of the FTDI? If not, you'll need to manually reset the ATmega328 when uploading.

As far as the rx and tx goes, I'm not 100% sure which is which on the FTDI cable, so I've tried switching the two, but each time I get the same result. I haven't put in a capacitor for the reset, so I'll have to manually reset the atmega while uploading, now, what exactly is the method for doing so? I've never had to manually reset an arduino or arduino clone, so I'm at a loss for how to do that. I've included a screen capture of my schematic so you can take a look to see if there's something wrong with that.

The BPX65 connected to pin 30 isn't installed, nor is the resistor along side it - it's there as a place holder for an LDR for later use. JP1 is what I'm using for uploading the sketch, and JP2 is what I used for burning the bootloader.

Connect RTS to 3V with a 10K resistor.
Connect RTS to a pin called DTR, the FTDI adapter Reset will connect to DTR.

Otherwise, with no cap, put a normally open switch from RTS to GND.

Press & hold the switch. Start the Download. When the IDE displays "compiled xxx of 32xxx bytes" (something like that), Release the RTS switch.
May take a couple of tries to release at the right time.
Might also help to put a diode across the RTS resistor, cathode to 3V and anode to RTS.

CrossRoads:
Connect RTS to 3V with a 10K resistor.
Connect RTS to a pin called DTR, the FTDI adapter Reset will connect to DTR.

Otherwise, with no cap, put a normally open switch from RTS to GND.

Press & hold the switch. Start the Download. When the IDE displays "compiled xxx of 32xxx bytes" (something like that), Release the RTS switch.
May take a couple of tries to release at the right time.
Might also help to put a diode across the RTS resistor, cathode to 3V and anode to RTS.

The FTDI cable I have doesn't have labeled pins because it's the cable from Adafruit with the female header on the end and the FTDI chip in the male USB connector. Also, you mentioned a capacitor in your reply but didn't explain where it gets connected.

Have you looked at the FTDI Cable data sheet?

The cap goes between the FTDI Cable RTS and the reset pin on the board. When RTS is asserted, the cap helps create a momentary low pulse to reset the board.

Alright, I've put a 100nF cap in between the reset on the ATMEGA and DTR of the FTDI cable and still no luck. I also threw in a 10K Ohm resistor to V+ along with the cap, and again, no luck.

Here's what I have in terms of connections, from FTDI > ATMEGA328P

GND > GND
CTS# > GND
VCC > V+
TXD > RXD
RXD > TXD
RTS# > RTS

I referenced the boarduino and lilipad schematics to verify the CTS# was connected to GND in the circuit

Which Bootloader did you burn?

Now that you mention it, I'm not sure, :blush:

I loaded the ArduinoISP to the boarduino, hooked up the mosi/miso/sck/rst/gnd/v+ to the target board, and just burned the bootloader via arduinoISP. I wasn't given an option to choose which bootloader. This might be the issue. Where can I get the lilipad bootloader and use that to put onto the new board?

EDIT: Before I burned the bootloader, I selected Lilypad Arduino w/ atmega328 as the board in the Tools menu. Not sure if this is what you're talking about.

"Before I burned the bootloader, I selected Lilypad Arduino w/ atmega328 as the board in the Tools menu."
Is a standard Lilypad using 8 MHz?
From Arduino hardware page for Lilypad: "Clock Speed 8 MHz"

If so, that could be the problem as your board is running at 16 MHz per your schematic.

I am totally new to microprocessors.
I just got my first Arduino [R3].
I copied a simple program from a youtube tutorial -- it blinks the on-board LED (pin 13).
No breadboard; no components -- nothing else but an Arduino.
I am using the Version 1.0.1 of the Arduino program.
The program tested my sketch, and said it was fine!
When I tried to upload the sketch, I got an error message: avrdude: stk500_getsync(): not in sync: resp=0x00
I have no idea what that means!
Do you???

So, I just found the solution! (Oh Happy Day!)
I was watching another tutorial, and it said the "Send" [Tx] and the "Receive [Rx] lights [LEDs] on the Arduino Board should flash as the Sketch is being uploaded; I noticed that those LEDs were NOT flashing as I tried to upload my Sketch. I happened to check my Device Manager on my computer; under "Ports (COM & LPT)," my Arduino was listed (as were two Bluetooth devices I have connected to my computer). I noticed the Arduino was showing that it was connected to COM5 -- instead of COM3 (which is what I had indicated in the Arduino Program). So, I went back to the Arduino program; under TOOLS, I selected SERIAL PORTS; I changed the item selected from COM3 to COM5 (what was listed in the Device Manager). I uploaded my Sketch again, and everything works just fine!!!!!!

CrossRoads:
From Arduino hardware page for Lilypad: "Clock Speed 8 MHz"

If so, that could be the problem as your board is running at 16 MHz per your schematic.

I hadn't thought of that until last night. Is there a way to modify the Lilipad bootloader to run at 16Mhz, or am I going to have to get 8Mhz crystals/resonators?

Also, what is the reason I cannot burn the regular Arduino bootloader to the 328P and have to use the Lilypad version?

@rmhutchins - way to go!

@smkoberg - that'd be perfectly acceptable! You can install the Optiload bootloader, and select Uno as the board type for downloading sketches.

Here's an update:
While messing with the arduino IDE and trying to get a bootloader and sketch uploaded to the atmega328p, the chip got really hot and I feared I may have fried it. So, I brought out my pocketAVR programmer, from Sparkfun, and successfully loaded a simple program that blinked the LEDs for all pins on portB. This worked fine, so I knew that the 328p wasn't fried. Furthermore, I downloaded and installed the newest version of the arduino IDE. Previously, I was working on version 0022 and figured a newer version might help. I came to find out that you can burn bootloaders and sketches to an atmega listed in the boards menu using an external programmer. Unfortunately, I don't remember exactly what steps I took to get something to happen, but I managed to get the sketch onto the 328p and fade random LEDs like I wanted; however, after a few minutes of leaving the chip on, the board started acting funny and only the LED connected to pin 9 (PD5) would work.

I think the way I got it to work initially was to use avrdude to burn the optiboot_atmega328.hex file to the board, then through the arduino IDE, upload the sketch using the "Upload Using Programmer" command under the file menu. When I did this, I don't remember which board I had selected, but I know I was using the USBtinyISP as the programmer under the tools menu. Again, whatever I had done worked fine for a short period, then after a few minutes, the LEDs just stopped illuminating, with the exception of the one mentioned above.

smkoberg:
I think the way I got it to work initially was to use avrdude to burn the optiboot_atmega328.hex file to the board, then through the arduino IDE, upload the sketch using the "Upload Using Programmer" command under the file menu. When I did this, I don't remember which board I had selected, but I know I was using the USBtinyISP as the programmer under the tools menu. Again, whatever I had done worked fine for a short period, then after a few minutes, the LEDs just stopped illuminating, with the exception of the one mentioned above.

If the Burn bootloader or Upload using programmer methods are failing it could be because of the LED you have put on the MOSI pin.

Try removing it temporarily or replace the current limiting resistor with a much bigger one. That 470 Ohm resistor will work as a pull-down resistor and might prevent SPI from working properly.
I would recommend the same for the RX led resistor.

Did you have current limit resistors with the LEDs? If not, you may hae damaged things that way.

Okay, I'm not sure what happened, but something seems really wrong now.

I do have current limiting resistors for each LED which I calculated using the LED calculator over at led.linear1.org, and now when I try uploading code compiled in avrstudio and uploaded with my pocketAVR programmer via AVRDUDE, nothing happens.

While programming, the LED connected to the MOSI pin flashes, but when the programming is done, nothing happens.

I'm going to remove the LED associated with that LED and try uploading the code again to see if that fixes any issues.

edited for coherence

Well, I removed all the current limiting resistors for the LEDs, uploaded a program compiled in AVRStudio which blinks all the LEDs (code below), and uploaded it to the ATMEGA328P. When I did this, it seemed okay, but when I soldered the resistors back on, put in the battery, and flipped the switch, nothing happened. I think I may have a dead board.

CODE:

#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
  // Set Port B pins as all outputs
  DDRB = 0xff;

  // Use this function from delay.h to delay for 1 second
  _delay_ms(1000);        

  // Set all of Port B pins as HIGH
  PORTB = 0xff;
  PORTD = 0Xff;
  

  return 1;
}

And here is the what AVRdude gave me when I uploaded the .hex file:

C:\Users\sethTriad\Documents\AVRStudio\AVRGCC3\AVRGCC3\Debug>avrdude -c usbtiny
-B 1 -p m328p -U flash:w:AVRGCC3.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e950f
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed

         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "AVRGCC3.hex"
avrdude: input file AVRGCC3.hex auto detected as Intel Hex
avrdude: writing flash (3296 bytes):

Writing | ################################################## | 100% 2.14s



avrdude: 3296 bytes of flash written
avrdude: verifying flash memory against AVRGCC3.hex:
avrdude: load data flash data from input file AVRGCC3.hex:
avrdude: input file AVRGCC3.hex auto detected as Intel Hex
avrdude: input file AVRGCC3.hex contains 3296 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 1.64s



avrdude: verifying ...
avrdude: 3296 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.


C:\Users\sethTriad\Documents\AVRStudio\AVRGCC3\AVRGCC3\Debug>