Problems programming Atmega 328p-au TQFP

Hi,
I’m not new to electronics but I am new to both arduino and atmel chips. I have an arduino uno which I’ve used to program only itself and had no problems with. I have tried to search the forum for a solution but haven’t found one, only part solutions to some of my problems which have all been solved now, just this final major hurdle to go…

This is a long one so you might want to get a snack for the journey :slight_smile:

I’m having extreme difficulties programming my newly bought blank Atmega 328p-au TQFP chip that I’ve mounted on a PCB.

The PCB is not fully populated at this point, just the MCU, reset pull-up resistor, resonator and wires for the i/o programming and power lines.

So effectively all that’s in the circuit is:

Atmega 328p-au TQFP chip (Farnell order code: 1715486):

Pin1,2,9,10,11,12,13,14,19,20,22,23,24,25,26,27,28,32: Not Connected

Pin 3,5, 21: Ground

Pin 4, 6, 18: +5V

Pin 7: XTAL 1
Pin 8: XTAL 2

(these pins are connected together via a 1M resistor and then to a 16MHz resonator with 3 pins, central connected to ground, other two pins connected to 7 and 8 of MCU. It has internal capacitors so no need for externals, according to datasheet! http://www.farnell.com/datasheets/95544.pdf )

Pin 15: MOSI
Pin 16: MISO
Pin 17: SCK
Pin 29: RESET (connected to RESET header pin and then via a 10k resistor to +5V)

Pin 30: RXD
Pin 31: TXD

I’ve checked all the pins and outputs with a multimeter continuity check and everything appears fine, no dry joints or short circuits, all pin to pin resistances are as low as expected and resistor values correct.

I have used the ArduinoISP file, optiloader (Bill Westfield) and an alternative version of ArduinoISP from Nick Gammon (http://www.gammon.com.au/forum/?id=11637) and they all install the bootloader fine (and Nick’s program reads it back to confirm it’s on so it definitely works with the MOSI/MISO).

However, when I then try and program the MCU with a sketch using the Arduino IDE I get this error:

avrdude: stk500_getsync(): not in sync: resp=0x00

Using a number of different combinations of Board and Programmer selected (all the tutorials just say Arduino Uno and AVRISPmkII but as I’m desperate I’ve tried them all in different combinations). I did put a capacitor across the Arduino reset and checked that it wasn’t just reprogramming itself (Blink is such a useful tool!) so it’s not that.

I also reloaded the bootloader with an option for using the 8MHz internal clock (Nick’s program gives two options, 8Mhz internal or 16Mhz external) and tried again but using the lilypad328 as the board (his suggestion) with no success (I also tried the other boards again just incase, same result). I then reloaded the 16Mhz external version and verified this using his program to see that it had installed correctly.

I then tried with a standalone USB to serial board (http://onecall.farnell.com/ftdi/mm232r/development-kit-usb-uart-module/dp/1146037), after loading the bootloader with the above system. I connected up the board to give a 5V output (confirmed with multimeter) and then connected the RTS pin from the serial board via a series 0.1uF capacitor to my reset pin, and the serial TXD and RXD to the MCU’s RXD and TXD respectively (I also tried it the other way round on the off chance, it gave the same error).

Serial TXD > MCU RXD
Serial RXD > MCU TXD
Serial RTS > 0.1uF > MCU RESET (still also connected to the 10k to +5V)
Serial VCC5V > MCU +5V
Serial GND > MCU GND

When I connect up the serial output to the MCU and try and program anything (even tried BareMinimum) I get the same error.

I am using Board>Arduino Uno and Programmer>AVRISPmkII. I have the correct serial port selected (port 10 for breakout, port 9 previously for arduino), I have also tried using Board> Arduino Duemilanove and tried Arduino Nano (both with 328 obviously) and got the same result.

I have tried the same sequence with Programmer>AVRISP and USBasp and USBTinyISP on the off chance and all give the same result.

Does anyone else have any idea what else I could try and/or how to fix this problem?

The only thing left that I’m doubting is the resonator but the schematic for the arduino has a similar setup so I can’t see why that would be an issue, and wouldn’t that stop me re-programming the bootloader (which I’ve done several times) if the clock wasn’t working?

I’ve just borrowed an avr dragon and installed the software but have absolutely no idea how to use it. I’ve seen a couple of suggestions about checking fuses but I’ve no idea how to do that, the program by Nick gives me a load of hex numbers back but when I look on the 328 datasheet I can’t work out what they’re supposed to mean, it just says you should set the fuses but doesn’t give any values that match up with the hex numbers seen in the fuse output.

Thanks for reading if you got this far, and thank in advance for any help you might offer, no suggestion is too obvious! (I really am a pure newbie when it comes to this chip :confused: )

Thanks,

Russel

Does your board have a reset button?

Russel77:
...

Pin 15: MOSI
Pin 16: MISO
Pin 17: SCK
Pin 29: RESET (connected to RESET header pin and then via a 10k resistor to +5V)

Pin 30: RXD
Pin 31: TXD

I’ve checked all the pins and outputs with a multimeter continuity check and everything appears fine, no dry joints or short circuits, all pin to pin resistances are as low as expected and resistor values correct.

I have used the ArduinoISP file, optiloader (Bill Westfield) and an alternative version of ArduinoISP from Nick Gammon (http://www.gammon.com.au/forum/?id=11637) and they all install the bootloader fine (and Nick’s program reads it back to confirm it’s on so it definitely works with the MOSI/MISO).

However, when I then try and program the MCU with a sketch using the Arduino IDE I get this error:

avrdude: stk500_getsync(): not in sync: resp=0x00

What were TxD and RxD connected to? Up to this point, you made not mention of a USB-to-serial converter. Without one or at least a serial connection to the PC (for which you would need to do level-shifting), you can't upload a sketch via the bootloader. However, you can instead program a sketch via ICSP, using the same connections you had when uploading the bootloader. You just need to select "Upload using programmer" in the menu. This is how I upload sketches on boards I build - I never use a bootloader.

Russel77:
...

I then tried with a standalone USB to serial board (http://onecall.farnell.com/ftdi/mm232r/development-kit-usb-uart-module/dp/1146037), after loading the bootloader with the above system. I connected up the board to give a 5V output (confirmed with multimeter) and then connected the RTS pin from the serial board via a series 0.1uF capacitor to my reset pin, and the serial TXD and RXD to the MCU’s RXD and TXD respectively (I also tried it the other way round on the off chance, it gave the same error).

I think the Arduino upload code is designed to pulse DTR, not RTS. Alternatively, you can use a reset button and press it at the right time.

Your ceramic resonator is fine, I use them all the time. The 1M resistor is not needed, there is already one in the mcu.

it does but I didn't initially wire it up because my understanding was that the ISP cable would do the reset. However, i've since added the reset button to take the RESET pin low and tried pressing it before the programming initiates but to no improvement.

Here's a picture of what's currently connected, any pin without something on it listed in the first post is still not connected, the rest of the board is unpopulated, but the reset switch has now been attached.

Thanks for the replies so far,

I tried clicking on upload using programmer and all it does is reprogram my arduino not the slave board it's connected to.

I currently have the ArduinoISP sketch installed on the arduino,

the MISO, MOSI, RESET and SCK wires from the arduino connected to my PCB,

a 10uF capacitor between the Arduino RESET and GND pin (to stop it programing the Arduino... in theory!)

Then I have Board set to Arduino and Programmer set to Arduino as ISP.

I'll just run through it all again slowly and check the output on pin 13 to see if it gives me a blink, back in 10mins (don't have a scope in my office)

dc42 you are my hero, after much faffing about I realised that what I thought was an error was actually it blinking back to me... it's been a long night!

So I got it to work in the end by programming the Arduino with the ArduinoISP sketch, connecting up all the correct ICSP as before then putting the capacitor over the reset and then selecting programmer as Arduino as ISP, then doing what you suggested and just clicking on upload using programmer.

I've tried it with a few different options and it works fine so this is the solution, using the program as it was intended still doesn't work but I don't care so long as I can program :slight_smile:

Thank you so much for taking the time to help an idiot in need, it is very much appreciated!

If I knew where you lived i'd buy you a beer, you've just saved me hours of trying to learn avr studio, I can now get on with finishing the board! :slight_smile:

Russel77:
dc42 you are my hero, after much faffing about I realised that what I thought was an error was actually it blinking back to me... it's been a long night!

So I got it to work in the end by programming the Arduino with the ArduinoISP sketch, connecting up all the correct ICSP as before then putting the capacitor over the reset and then selecting programmer as Arduino as ISP, then doing what you suggested and just clicking on upload using programmer.

I've tried it with a few different options and it works fine so this is the solution, using the program as it was intended still doesn't work but I don't care so long as I can program :slight_smile:

Thank you so much for taking the time to help an idiot in need, it is very much appreciated!

If I knew where you lived i'd buy you a beer, you've just saved me hours of trying to learn avr studio, I can now get on with finishing the board! :slight_smile:

I'm glad you got it working. If you are programming via ICSP, you don't need the capacitor on reset or a reset button, just the pullup resistor to +5v. And if you're ever near Ash Vale, UK then you can buy me that beer!