Bootloader on SMD Atmega328P-AU - Page 1
Forum section: electronics / general

author: IanJ
author_rank: Unknown
timestamp: July 29, 2013, 06:34:18 am
content: Hi all,For a project I'm working on I am using an SMD Atmega328P-AU. I bought a few virgin 328P's and using a ZIF socket for the SMD 328P I built a small board with the ISP header on it and c/w crystal.First things first though, I took an Arduino Nano (V3 with 328P = same chip) and hooked up my ATTINY and made sure I could upload the bootloader to the Nano from the Arduino IDE........worked no problem.So then I tried my own 328P but got a device signature problem. Unfortunately, the Arduino IDE doesn't record what sig it found, it only responds with the sig it should be.Browsing the web it seens that on ocassion the avrdude.conf file needs modified with a new sig, so this I did but still no joy.So, I ran a command line session with avrdude and was able to get the sig that was found. I then modified the .cong file and voila was able to upload the bootloader to the 328P. I also verified that I could upload a sketch and it was able to run.Next, I took a 328P off a working Arduino Nano and hooked it up to my board and tried uploading the bootloader, but again it failed and I needed to change the signature......wtf!Existing original 328P sig = 1E 95 0FOther folks have said change it to 1E 95 14 and it should work.avrdude responded with - 00 01 02 (something like this, I'm typing from memory!)Ok so I got it to work, but I just wonder why I am getting a different signature from the SAME 328P with my board compared to the Nano.Ian.

author: c4757p
author_rank: Super Contributor
timestamp: July 29, 2013, 06:40:58 am
content: Signatures consisting of mostly zeros are often a sign of a poor connection or improperly configured fuses. Are you sure the upload was successful for the second chip?

author: IanJ
author_rank: Unknown
timestamp: July 29, 2013, 06:50:51 am
content: Quote from: c4757p on July 29, 2013, 06:40:58 amThe IDE reported the upload of the bootloader was successful. However, I'll upload a sketch to the 2nd chip tonight and see what happens. Come to think of it, the one I uploaded the sketch to was the one taken from the Nano so it's theoretically possible that although I was trying to overwrite the bootloader with a new copy, maybe it had actually failed (despite reporting upload success) and the original bootloader was still in place thus my test sketch worked. Hmmmm!The proof I guess will be to try all this on the virgin chip.Thanks for responding.Ian.

author: amyk
author_rank: Super Contributor
timestamp: July 29, 2013, 11:34:42 am
content: The 328P has 1E 95 0FThe 328 (no P) has 1E 95 14They're different.

author: Psi
author_rank: Super Contributor
timestamp: July 29, 2013, 11:50:37 am
content: Yes, signature 00 01 02 is a very common result when you have something wired or connected wrong.I've personally seen it in the following situations.1) The chip has MOSI/MISO/SCK/RESET/GND connected to a programmer but no 5V power is connected.The MCU will often "run" as power will backflow from the programmer into the SPI pins and get onto the chips power rail through the clamping diodes. So the chip kind of answers ISP requests but is unable to actually read or write its own flash.2) The cable between the programmer and chip is too long. Anything over 1 meter and you can have issues.3) A programming cycle has been aborted halfway through and the chip is now in a weird state. Most of the time if you abort a programming cycle everything is fine but occasionally the chip will get stuck.A power cycle fixes this but you have to kill all power. Not just VCC because of the effect mentioned in 1) above. (pulling Reset low for a sec doesn't seem to work for this fault)

author: A Hellene
author_rank: Frequent Contributor
timestamp: July 29, 2013, 01:43:34 pm
content: The AVR line has two FLASH memory spaces: The firmware memory space, which is fully accessible by the User in R/W fashion, and the calibration memory space where the calibration/signature/etc. chip data is stored. That special memory space size is one page long (varying from 8..128 words for every chip family or FLASH size) and it is accessible through specialundocumentedprogramming instructions.Now, if the ISP data cable is long enough (or poorly constructed) a programming instruction opcode can be corrupted and randomly match the opcode of an undocumented instruction, most commonly resulting in erasing the target chip calibration data space! That happens because the ISP protocol erase_cal_space instruction opcode is only four bytes long (just as the FLASH/EEPROM chip_erase instruction also is), and different in one bit only from the chip_erase opcode! The documented FLASH/EEPROM Memories Chip_Erase opcode is '0xAC 0x80 0x00 0x00' and the undocumented erase_cal_space opcode is '0xAC 0xC0 0x00 0x00'.I have found out some of those undocumented opcodes by using a custom, fully configurable AVR programmer I designed back in 2002, that supports all the ISP/HVPP/HVSP modes, by later adding to its firmware some intelligent opcode searching/verification algorithms.Custom AVR ProgrammerAnyway, if the calibration data space is erased, then the chip signature will be reset and read FF.FF.FF! The signature will be read as 00.01.02 if the programming protocol is parallel (HVPP) and the target chip is missing, resulting in the programmer hardware reading back the address it has just sent to the missing target chip, since the same 8-bit data port of the target chip is used for data and for address transmission as well. The same also applies to the serial ISP programming protocol.These are the contents of the first four data words (residing at the calibration address space 0x000..0x003) of the 64 data words stored at the calibration data space of a ATMega328-PU:Custom AVR Programmer, m328 calibration space 0x000..0x003: The cursor points at the higher nybble of the ow byte of the Word at 0x, according to the obscure '000L' information at the beginning of the first LCD line.The User accessible data are the signature bytes (1E.95.14) and the 8 MHz oscillator calibration byte (0x8F).This is the complete calibration space data dump of that specific chip above, as reported by the programmer through its UART line:Code:ATnega3280x0000: 1E.8F 95.FF 14.D1 FF.26 FF.0B FF.17 FF.FF 4A.310x0008: 34.30 36.34 FF.03 1E.04 17.01 12.05 13.05 FF.FF0x0010: FF.FF FF.FF FF.FF FF.FF FF.FF FF.FF FF.FF B8.870x0018: BC.55 53.63 AE.8F C3.46 B9.75 99.0F 57.0B D4.0E0x0020: FF.FF FF.FF FF.FF FF.FF FF.FF FF.FF FF.FF FF.FF0x0028: FF.FF FF.FF FF.FF FF.FF FF.FF FF.FF FF.FF FF.FF0x0030: FF.FF FF.FF FF.FF FF.FF FF.FF FF.FF FF.FF FF.FF0x0038: FF.FF FF.FF FF.FF FF.FF FF.FF FF.FF FF.FF 75.06These are the signature bytes read with the m328 programming socket populated in the first picture, and with the socket empty in the second one:Custom AVR Programmer, m328 signature readCustom AVR Programmer, empty socket signature read-George

author: IanJ
author_rank: Unknown
timestamp: July 29, 2013, 05:26:04 pm
content: Hi all,Fixed.Fitted a known good 328p (with bootloader) and FTDI wouldn't work (to upload a sketch), scoped the comms and found it was inactive. Schoolboy error, found I'd tied the pull up resistor on !RESET low instead of high! Dear oh dear!So now, Avrdude command line check now reports proper signature, am able to upload the bootloader using the ISP header, and able to upload a sketch using the FTDI header. Job done.Couple pics below if anyone is interested.Ian.

author: joseignacio
author_rank: Newbie
timestamp: January 29, 2014, 02:55:11 pm
content: Hello Ian,I'm trying exactly the same as you did: I need flashing and uploading a sketch into a Atmega328p-AU before assembling it in the PCB. I want to make a shield using a TQFP32 adapter I bought in ebay and adding the resistences and capacitors needed. The shield will be placed on a arduino UNO working as ISP, and would do both things: burning the arduino bootloader into a new atmega328p-AU and programming a sketch.Did you make any schematic of your design? I am a little with the connections needed between the new atmega and the arduino working as ISP.Thank you!Greetings from Spain.

author: old gregg
author_rank: Regular Contributor
timestamp: February 04, 2014, 08:14:42 pm
content: hi,I just want to know if any of you know the device signature of the atmega328P-PU ? there are several imformations on the P and non-P version , but not on this "-PU"thanks

author: Monkeh
author_rank: Super Contributor
timestamp: February 04, 2014, 08:54:33 pm
content: -PU is the package. It is a 328P.There are many 'informations' here:http://www.atmel.com/Images/doc8161.pdf

author: paulie
author_rank: Frequent Contributor
timestamp: February 04, 2014, 08:56:20 pm
content: -PU and -AU refer to avr package type and have nothing to do with m328 or signature. 328p and 328 can both be programmed without resorting to conf file editing by using "-F" option. relatively safe for all operations unless changing fuses in which case you should be very careful.

author: old gregg
author_rank: Regular Contributor
timestamp: February 05, 2014, 06:12:51 pm
content: Quote from: Monkeh on February 04, 2014, 08:54:33 pmthanks.It's odd. Avrdude (and studio6 when it was installed) doesn't recognize the chips as 328p . Both gave different device signature and therefore I can't program the chip. If it's matter of package , the signature should be correct.

author: scientist
author_rank: Frequent Contributor
timestamp: February 06, 2014, 05:09:39 am
content: Quote from: IanJ on July 29, 2013, 05:26:04 pmHow much are those sockets, about?

author: old gregg
author_rank: Regular Contributor
timestamp: February 06, 2014, 02:03:11 pm
content: Quote from: old gregg on February 05, 2014, 06:12:51 pmmy bad. I managed to get that thing working. Seems that those bloody dodgy wires were responsible.

author: amyk
author_rank: Super Contributor
timestamp: February 08, 2014, 12:51:54 pm
content: Quote from: scientist on February 06, 2014, 05:09:39 amThat appears to be an IC51-0324-1498, whichis about $45USD.

author: zapta
author_rank: Super Contributor
timestamp: March 19, 2014, 05:30:16 am
content: Was this solved? If not, one difference between blank and programmed 328p's is that the blank ones needs slower programming speed. 250khz at most. If you are using avrdude, look for the -B flag. The reason is that the blank 328p's are programmed to use a 1Mhz clock and the programming clock can be at most 1/4 of that.This is how I program blank 328p's to look like Arduino Pro Mini 16Mhz, 5V with my program.https://github.com/zapta/linbus/blob/master/analyzer/firmware/icsp_program_all.sh

author: paulie
author_rank: Frequent Contributor
timestamp: March 20, 2014, 04:25:37 pm
content: ive found modern cheapo chinese usbasp treat 1mhz and 16mhz the same without special commands. just another of the many advantages over the "real" programmers.

author: moreab
author_rank: Newbie
timestamp: July 03, 2016, 06:43:16 am
content: Please Help,I am making standalone atmega328p-au smd version. I brought IC and soldered on my own board with reset and crystal ckt. The board is detected by AVR programmer by SPI protocol using avrdude but when I try to upload boot-loader or any sketch using avrdude it shows rc=-1 error and then after never detected. I also checked using Arduino UNO board as programmer but giving signature error.What should I do??

author: Neverther
author_rank: Regular Contributor
timestamp: July 03, 2016, 08:12:45 am
content: Try reducing the clock first if you use avrdude. They ship with 8Mhz internal rc oscillator and DIV8, so running at 1Mhz.In avrdude manual it says that by default the bitclock is for around 4Mhz devices.Try with avrdude with "-B 255" or something and see if it responds.If it doesnt work, your programmer cannot set bitclock or you have wrong clock source selected or you have connection issue.

author: moreab
author_rank: Newbie
timestamp: July 03, 2016, 06:21:11 pm
content: I downloaded all my project code on arduino nano board ( has bootloader ) and desoldered the atmega328p-au IC and placed on my own board(has proper reset and 16MHz clock) but still showing erroravrdude.exe: set SCK frequency to 1500000 Hzavrdude.exe: error: programm enable: target doesn't answer. 1avrdude.exe: initialization failed, rc=-1Double check connections and try again, or use -F to overridethis check.what should I do?

author: janoc
author_rank: Super Contributor
timestamp: July 03, 2016, 10:12:52 pm
content: Quote from: old gregg on February 05, 2014, 06:12:51 pmCareful - ATMega328 and ATMega328p aredifferent siliconandbothexist in the -AU (TQFP) and -PU (DIP) packages. So it is normal that the signature between normal 328 and 328p is different, regardless of the package - the latter is the PicoPower version that supports some extra low power stuff, if I remember correctly.

author: janoc
author_rank: Super Contributor
timestamp: July 03, 2016, 10:16:26 pm
content: Quote from: zapta on March 19, 2014, 05:30:16 amYep, got bitten by this recently too - you need to specify something like -B 10 or even -B 100 before it will program. A virgin ATMega is configured from the factory to run on the internal 8MHz RC oscillator but has the CLKDIV8 fuse programmed, dividing the clock by 8 = 1MHz system clock

author: moreab
author_rank: Newbie
timestamp: July 05, 2016, 09:27:34 am
content: yesterday I tried burning Arduino uno bootloader in atmega328p-au it is downloaded successfully then I changed fuses according to UNO board from board.txt when I tried changing Lock Bit(LB)=0x0f it shown meavrdude.exe: set SCK frequency to 1500000 Hzavrdude.exe: error: programm enable: target doesn't answer. 1avrdude.exe: initialization failed, rc=-1Double check connections and try again, or use -F to overridethis check.After that IC is never detectedwhat should I do?

author: sleemanj
author_rank: Super Contributor
timestamp: July 05, 2016, 09:51:16 am
content: Quote from: moreab on July 05, 2016, 09:27:34 amWhich sets the fuses to use an external Crystal. If you do not have an external Crystal attached, then it's not going to work. You can rescue it by attaching an external crystal, or injecting a clock signal into XTAL1 pin (8MHz is traditional) then reprogramming fuses to use the internal oscillator.

author: yamadanao
author_rank: Newbie
timestamp: July 03, 2017, 09:19:37 am
content: Thank you for your post,here is thedate sheet of Atmega328Pfor your reference.