Flashing atmega328 with arduino - Page 1
Forum section: electronics / general

author: jacobfeder
author_rank: Contributor
timestamp: April 21, 2016, 09:46:40 pm
content: Hi,I am a newbie here so firstly hello and happy to be here.I have a custom board (an LVDT driver) and am trying to use an atmega328 to collect data from an ADC and drive a LCD alphanumeric display. I bought the 328 chip (not 328p!) on digikey and soldered it onto my board. I have tried in vain to flash the arduino bootloader, burn the fuses, or get any sign of life out of the chip. Attached is a schematic and picture of the setup. I have an external +-15V and +5V supply going to the LVDT board. I am trying to use an arduino uno board to flash the atmega328 through an ICSP header I put on the board (I just have wires soldered in temporarily). I have checked continuity for all connections. I added bypass caps both from vdd to gnd and on the reset pin to gnd as was recommended in a few tutorials I found. I tried powering the LVDT board directly from the arduino, and also using the separate power supply.When I try to flash it (I've tried both with the arduino GUI and avrdude cmd line tool), I get the message:Code:avrdude -c arduino -p m328 -P /dev/cu.usbmodem1411avrdude: AVR device initialized and ready to accept instructionsReading | ################################################## | 100% 0.00savrdude: Device signature = 0x1e950favrdude: Expected signature for ATmega328 is 1E 95 14Double check chip, or use -F to override this check.avrdude done. Thank you.I get this same error message when I completely unplug all connections to the LVDT board. In other words, it seems like it isn't communicating with the chip at all. If I change the device type to atmega328p it happily reports that all the fuses are 0'ed out.Code:avrdude -c arduino -p m328p -P /dev/cu.usbmodem1411avrdude: AVR device initialized and ready to accept instructionsReading | ################################################## | 100% 0.00savrdude: Device signature = 0x1e950favrdude: safemode: Fuses OK (H:00, E:00, L:00)avrdude done. Thank you.Any ideas on how to debug this problem?Thanks!

author: klunkerbus
author_rank: Unknown
timestamp: April 21, 2016, 10:25:06 pm
content: What is the actual part number of the ATMEGA328 on the board? I believe the device signature of 1E 95 0F being read by the programmer is in fact the signature for a 328P.

author: jacobfeder
author_rank: Contributor
timestamp: April 21, 2016, 11:22:41 pm
content: The part number is ATMEGA328-AUR (digikey ATMEGA328-AURCT-ND). However, it gets the same error when the programming pins are unplugged, which makes me think there is something else going on...

author: dannyf
author_rank: Super Contributor
timestamp: April 21, 2016, 11:43:15 pm
content: Those are the right signatures for the respective chips. So the isp is working.Looks to me that avrdude is treating a 328 as 328p when checking the signature. If the code is designed to run the 328 as well as 328p, use the -F switch to override.

author: jacobfeder
author_rank: Contributor
timestamp: April 22, 2016, 02:55:33 am
content: It seems to me like it's confusing the chip being used as the programmer and the chip being programmed. The Uno has a 328p but I am trying to target a 328. When I completely disconnect the 328 avrdude still thinks it's programming a 328p. What is the expected behavior of avrdude if nothing is connected?

author: westfw
author_rank: Super Contributor
timestamp: April 22, 2016, 04:37:39 am
content: QuoteYou realize that that command doesn't actually flash anything...If you're using an arduino and the ArduinoISP sketch, you want your avrdude command to look like:avrdude-c stk500v1 -b 19200-p m328 -P /dev/cu.usbmodem1411With the command you're using now, you probably end up talking to the bootloader on the arduino, and it doesn't handle fuses.(This probably means you don't have the 10uF cap between the Arduino RESET and GND that you need to stop its auto-reset, either. A lot of the "tutorials" leave that out.)One of the better tutorials is Nick Gammon's:http://www.gammon.com.au/breadboardBut it does use his custom arduino sketches for doing the programming, rather than ArduinoISP/AVRDude, making it somewhat less flexible.

author: sleemanj
author_rank: Super Contributor
timestamp: April 22, 2016, 05:55:13 am
content: The board you have selected in your Arduino IDE will be intended for the 328p, and it passes this information to avrdude, which complains when it finds a 328 on the end of the wire.Since we are talking Arduino here, you could install my DIY Atmega8 Series boardshttps://github.com/sleemanj/optiboot/blob/master/dists/README.mdthe you can choose exactly what your DIY board is for burning the bootloader.Otherwise a quick kludgy fix,Locate your avrdude.confOpen it in your favourite text editorLocate "0x1e 0x95 0x14"Change to "0x1e 0x95 0x0f"SaveThis will fool avrdude into thinking it saw a 328p, now you can burn the (328p) bootloader, then reverse the changes and you can upload over serial (because you uploaded a 328p bootloader, the chip will report as a 328p when communicating to said bootloader, so you have to reverse the changes after you have burnt the bootloader and start uploading over serial because avrdude will think it is talking to a 328p again).

author: Kilrah
author_rank: Unknown
timestamp: April 22, 2016, 09:47:45 am
content: As westfw said with your command you're accessing the MCU on the arduino board, not your target.

author: jacobfeder
author_rank: Contributor
timestamp: April 22, 2016, 02:45:52 pm
content: Thank you everyone for the replies. Just to clarify on what westfw said:1) I do realize that the command doesn't flash anything; I was using it to verify that I was actually communicating with the chip (getting non-zero fuse values reported)2) Why do I need to use "stk500v1" as the programmer? The avrdude documentation says that if you are using the arduino as the programmer you should use the keyword "-c arduino". I find that a bit confusing.3) I did add the 10uF cap from reset to gndI will give it a try with "-c stk500v1".Thanks again.

author: westfw
author_rank: Super Contributor
timestamp: April 23, 2016, 02:11:13 am
content: Quote"-c arduino" is for talking to the arduino bootloader. It uses a subset of the stk500v1 protocol, and has some extra code to do auto-reset.The ArduinoISP sketch implements a somewhat different subset of the stk500v1 protocol and should be used with "-c stk500v1"QuoteWatch the arduino running arduinoISP to see if the pin13 LED blinks three times rapidly when you issue the avrdude command; that would be a sign that it reset and is running the bootloader, which is not what you want.QuoteDont forget the "-b 19200", which is important as well. It prevents you from accidentally talking to the bootloader (which runs at 115200bps), so you'll get failures instead of mysterious responses from the wrong chip.

author: jacobfeder
author_rank: Contributor
timestamp: April 24, 2016, 10:48:38 pm
content: That makes sense.It turns out my problem was a poorly connected pin.Thanks again for the help.