-
Programming an external ATmega168 with an Arduino Duemilanove
Posted by
Randall W. Lott
on 19 Jul, 2012 20:08
-
First of all; I'd like to apologize if there has been a topic on this already.
My goal is to program the QFP ATmega168 that has been integrated into my product.
I have a standard 6-pin ICSP connector on the rear of my housing that connects to the following pins on the ATmega168:
4,6,18: +5VDC
17: SCK
16: MISO
15: MOSI
29: RESET
I also have an Arduino Duemilanove with an ATmega328.
What do I need to do to program the blank ATmega168 and start uploading sketches to my product?
Thank you kindly.
-
#1 Reply
Posted by
madires
on 19 Jul, 2012 20:20
-
-
-
-
#3 Reply
Posted by
Chet T16
on 19 Jul, 2012 23:36
-
Is this after uploading the arduinoISP sktch or when trying to upload it?
-
#4 Reply
Posted by
GabYoung92
on 19 Jul, 2012 23:53
-
I followed the tutorial here: http://arduino.cc/en/Tutorial/ArduinoISP
I get this error:
avrdude: stk500_getsync(): not in sync: resp=0x00
I've been having issues also programming a chip but,
You need up upload the arduinoISP sketch to the arduino.
Connect up the arduino to the external chip (there's instructions in the header of the sketch).
Then you need to change the board in the arduinoIDE under tools to match your chip.
And it's best to check what oscillator it's going to use by the fuses.
Then it should just be an upload.
-
-
Here is what I did:
- Opened ArduinoISP sketch under Examples.
- Chose Arduino Duemilanove w/ ATmega328.
- Uploaded sketch. This was successful.
- Wired the ICSP from my PCB, containing the blank ATmega168, to pins 10-13 on the Arduino.
- Selected "Arduino as ISP".
- Chose Arduino Pro under "boards".
- Attempted to Burn Bootloader.
- Got the previously mentioned error.
Thank you for the help!
-
#6 Reply
Posted by
GabYoung92
on 20 Jul, 2012 00:21
-
That's what I would have done
I was having a similar issue caused by the baud rate specified in the boards.txt file.
For example using
9600baud gave an out of sync error
19200baud worked but my chip wouldn't respond (An issue I think caused by the clock of the chip)
38400baud gave an out of sync error.
I would suggest using a different baud rate.
-
-
If you use that sketch be sure to fix the bug mentioned
here. Otherwise you can fry both the target MCU as well as your Arduino MCU.
-
-
Thank you all very much. I will try this today and I'll report back.
-
-
My ATmega168 is still not working after changing the ISP sketch file and adding a custom 8MHz ATmega168 entry in the Board.txt file. I'm getting:
In file included from SerialDisplay.cpp:42:
C:\Users\Randy\Desktop\Arduino\Install\hardware\arduino\cores\arduino/Arduino.h:212:26: error: pins_arduino.h: No such file or directory
Is it possible to upload sketches to an external ATmega168 with just the SPI bus? I'm reading that I need the RX/TX pins to communicate via USB (FTDI interface). My PCB is already designed and I have no header for these extra pins.
This is becoming pretty frustrating. I thought it would be a relatively easy task. I guess Dave had similar issues, but I can't find where he explained his processes and solutions.
I have much of my Arudino source code written. I'm going to love when I can actually send it off to my micro!
-
#10 Reply
Posted by
madires
on 21 Jul, 2012 12:27
-
My ATmega168 is still not working after changing the ISP sketch file and adding a custom 8MHz ATmega168 entry in the Board.txt file. I'm getting:
In file included from SerialDisplay.cpp:42:
C:\Users\Randy\Desktop\Arduino\Install\hardware\arduino\cores\arduino/Arduino.h:212:26: error: pins_arduino.h: No such file or directory
That file could be missing or not found because it's not in the search path. Recently I upgraded to 1.0.1 and had to update some #include statements because the name of a major header file changed.
Is it possible to upload sketches to an external ATmega168 with just the SPI bus? I'm reading that I need the RX/TX pins to communicate via USB (FTDI interface). My PCB is already designed and I have no header for these extra pins.
The ATmega has a serial and parallel interface for flashing. The serial one is simply the SPI bus + Vpp, Gnd and Reset (like the ICSP of the arduino). If you got a Bus Pirate you could also use it as an ISP programmer with avr-dude.
-
#11 Reply
Posted by
shebu18
on 21 Jul, 2012 18:42
-
I have not read the hole topic but out of sync is most of the time caused by not haveing a capacitator in series with the reset line. Look at the arduino scematic., close at the dtr line from the ftdi to the atmega reset pin. If this is ok or hase been mentioned please ignore this post.
Sent from my GT-I5800 using Tapatalk
-
-
I've come back with more information. Upon upgrading to 1.01, I receive this code when I try to burn the bootloader:
C:\Users\Randy\Desktop\Arduino 1.01\hardware/tools/avr/bin/avrdude -CC:\Users\Randy\Desktop\Arduino 1.01\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega168 -cstk500v1 -P\\.\COM4 -b19200 -e -Ulock:w:0x3F:m -Uefuse:w:0x07:m -Uhfuse:w:0xD9:m -Ulfuse:w:0xE2:m
avrdude: Version 5.11, compiled on Sep 2 2011 at 19:38:36
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2009 Joerg Wunsch
System wide configuration file is "C:\Users\Randy\Desktop\Arduino 1.01\hardware/tools/avr/etc/avrdude.conf"
Using Port : \\.\COM4
Using Programmer : stk500v1
Overriding Baud Rate : 19200
avrdude: Send: 0 [30] [20]
avrdude: Send: 0 [30] [20]
avrdude: Send: 0 [30] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]
AVR Part : ATMEGA168
Chip Erase delay : 9000 us
PAGEL : PD7
BS2 : PC2
RESET disposition : dedicated
RETRY pulse : SCK
serial program mode : yes
parallel program mode : yes
Timeout : 200
StabDelay : 100
CmdexeDelay : 25
SyncLoops : 32
ByteDelay : 0
PollIndex : 3
PollValue : 0x53
Memory Detail :
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
eeprom 65 20 4 0 no 512 4 0 3600 3600 0xff 0xff
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
flash 65 6 128 0 yes 16384 128 128 4500 4500 0xff 0xff
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
lfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
hfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
efuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
lock 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00
Programmer Type : STK500
Description : Atmel STK500 Version 1.x firmware
avrdude: Send: A [41] . [80] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [02]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [81] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [01]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [82] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [12]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [98] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
Hardware Version: 2
Firmware Version: 1.18
Topcard : Unknown
avrdude: Send: A [41] . [84] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [85] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [86] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [87] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [89] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
Vtarget : 0.0 V
Varef : 0.0 V
Oscillator : Off
SCK period : 0.1 us
avrdude: Send: A [41] . [81] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [01]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [82] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [12]
avrdude: Recv: . [10]
avrdude: Send: B [42] . [86] . [00] . [00] . [01] . [01] . [01] . [01] . [03] . [ff] . [ff] . [ff] . [ff] . [00] . [80] . [02] . [00] . [00] . [00] @ [40] . [00] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]
avrdude: Send: E [45] . [05] . [04] . [d7] . [c2] . [00] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]
avrdude: Send: P [50] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]
avrdude: AVR device initialized and ready to accept instructions
Reading | avrdude: Send: V [56] 0 [30] . [00] . [00] . [00] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
avrdude: Send: V [56] 0 [30] . [00] . [01] . [00] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
################avrdude: Send: V [56] 0 [30] . [00] . [02] . [00] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
################################## | 100% 0.07s
avrdude: Device signature = 0x000000
avrdude: Yikes! Invalid device signature.
Double check connections and try again, or use -F to override
this check.
avrdude: Send: Q [51] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]
avrdude done. Thank you.
I honestly have no idea what it means or if it's even communicating.
-
-
It means that avrdude is talking to the programmer (the Arduino firmware) but the programmer isn't talking to the target MCU.
The target MCU needs to be powered (same voltage as the programmer since I'm sure you don't have level converters) and needs to have a common GND with the programmer. Make sure all the ISP-related pins (SCK, MISO, MOSI and RESET#) are hooked-up properly.
Check to see that RESET is being pulled low by the programmer. Check SCK and MOSI for activity.
You should change your command line to NOT program the fuses and instead do something a little less dangerous until you get everything working. Something like this, perhaps:
avrdude -CC:\Users\Randy\Desktop\Arduino 1.01\hardware/tools/avr/etc/avrdude.conf -patmega168 -cstk500v1 -P\\.\COM4 -b19200 -t
This will put you in terminal mode. (Once it communicates successfully with the MCU.) Once in terminal mode you can inspect memory and whatnot to see if everything seems to be working.
-
-
Do you guys suggest using any passive components?
The guide shows a 10k Ohm resistor across SPI reset and 5V.
I've also seen people mention to use a capacitor. I'll be going to my house today, where my components are, so I am wondering if I need to grab some.
Thanks for the continued support.
-
-
I've always pulled-up RESET# with a 10k resistor and put a 10nF bypass cap on it as well--as recommended by
this Atmel app note.
-
-
Rather strangely, I'm getting an error after typing in the suggested codes in command prompt.
C:\Users\Randy>avrdude -CC:\Users\Randy\Desktop\Arduino 1.01\hardware/tools/avr
/etc/avrdude.conf -patmega168 -cstk500v1 -P\\.\COM5 -b19200 -t
error at C:\Users\Randy\Desktop\Arduino 1.01\hardware/tools/avr/etc/avrdude.con
f:332 unrecognized character: "w"
I'm not sure what to think of it. I freshly installed the Arduino IDE and WinAVR literally 5 minutes before attempting this, although "Google" told me that it could be a corrupted installation of the Arduino IDE.
-
-
I bet the WinAVR version of avrdude is what is in your path and the configuration file you specified in the Arduino folder is from an older version of avrdude. Try just leaving that -C option out.
avrdude -patmega168 -cstk500v1 -P\\.\COM5 -b19200 -t
-
-
I'm getting:
C:\Users\Randy>avrdude -v -v -v -v -patmega168 -cstk500v1 -P\\.\COM5 -b19200 -t
avrdude: Version 5.11-Patch#7610, compiled on Aug 31 2011 at 08:02:19
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2009 Joerg Wunsch
System wide configuration file is "C:\WinAVR-20100110\bin\avrdude.conf"
Using Port : \\.\COM5
Using Programmer : stk500v1
Overriding Baud Rate : 19200
avrdude: Send: 0 [30] [20]
avrdude: Send: 0 [30] [20]
avrdude: Send: 0 [30] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]
AVR Part : ATMEGA168
Chip Erase delay : 9000 us
PAGEL : PD7
BS2 : PC2
RESET disposition : dedicated
RETRY pulse : SCK
serial program mode : yes
parallel program mode : yes
Timeout : 200
StabDelay : 100
CmdexeDelay : 25
SyncLoops : 32
ByteDelay : 0
PollIndex : 3
PollValue : 0x53
Memory Detail :
Block Poll Page
Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW Max
W ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ---
-- ---------
eeprom 65 20 4 0 no 512 4 0 3600 36
00 0xff 0xff
Block Poll Page
Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW Max
W ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ---
-- ---------
flash 65 6 128 0 yes 16384 128 128 4500 45
00 0xff 0xff
Block Poll Page
Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW Max
W ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ---
-- ---------
lfuse 0 0 0 0 no 1 0 0 4500 45
00 0x00 0x00
Block Poll Page
Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW Max
W ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ---
-- ---------
hfuse 0 0 0 0 no 1 0 0 4500 45
00 0x00 0x00
Block Poll Page
Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW Max
W ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ---
-- ---------
efuse 0 0 0 0 no 1 0 0 4500 45
00 0x00 0x00
Block Poll Page
Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW Max
W ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ---
-- ---------
lock 0 0 0 0 no 1 0 0 4500 45
00 0x00 0x00
Block Poll Page
Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW Max
W ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ---
-- ---------
calibration 0 0 0 0 no 1 0 0 0
0 0x00 0x00
Block Poll Page
Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW Max
W ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ---
-- ---------
signature 0 0 0 0 no 3 0 0 0
0 0x00 0x00
Programmer Type : STK500
Description : Atmel STK500 Version 1.x firmware
avrdude: Send: A [41] . [80] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [02]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [81] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [01]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [82] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [12]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [98] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
Hardware Version: 2
Firmware Version: 1.18
Topcard : Unknown
avrdude: Send: A [41] . [84] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [85] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [86] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [87] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [89] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
Vtarget : 0.0 V
Varef : 0.0 V
Oscillator : Off
SCK period : 0.1 us
avrdude: Send: A [41] . [81] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [01]
avrdude: Recv: . [10]
avrdude: Send: A [41] . [82] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [12]
avrdude: Recv: . [10]
avrdude: Send: B [42] . [86] . [00] . [00] . [01] . [01] . [01] . [01] . [03] .
[ff] . [ff] . [ff] . [ff] . [00] . [80] . [02] . [00] . [00] . [00] @ [40] . [00
] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]
avrdude: Send: E [45] . [05] . [04] . [d7] . [c2] . [00] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]
avrdude: Send: P [50] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]
avrdude: AVR device initialized and ready to accept instructions
Reading | | 0% 0.00savrdude:
Send: V [56] 0 [30] . [00] . [00] . [00] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
avrdude: Send: V [56] 0 [30] . [00] . [01] . [00] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
Reading | ################# | 33% 0.13savrdude:
Send: V [56] 0 [30] . [00] . [02] . [00] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [00]
avrdude: Recv: . [10]
Reading | ################################################## | 100% 0.20s
avrdude: Device signature = 0x000000
avrdude: Yikes! Invalid device signature.
Double check connections and try again, or use -F to override
this check.
avrdude: Send: Q [51] [20]
avrdude: Recv: . [14]
avrdude: Recv: . [10]
avrdude done. Thank you.
I've done about a dozen Google searches for device signature errors. Someone mentioned that by lowering the SPI clock, it worked. I have no idea what I should try now.
Thanks again.
-
-
If you're using the latest version of that sketch then the SPI clock is running as slow as it can run unless you change the Arduino's system clock speed.
If you're comfortable with changing the clock to the internal RC then that is one way to slow the SPI clock down. This involves changing the fuse bits of the MCU on the Arduino board. If you get things wrong you can wind up bricking your Arduino.
-
-
I just did some quick calculations and it looks like the SPI clock speed should be okay. If the Arduino's clock is 16 Mhz then the SPI clock will be set to 125 kHz. This is assuming you're using version 0.4 of that sketch and haven't changed the spi_init() function:
void spi_init() {
uint8_t x;
SPCR = 0x53;
x=SPSR;
x=SPDR;
}
If your target MCU is running at 1 Mhz (factory default) then the 125 kHz should work according to the datasheet:
Datasheet, Page 308:
The minimum low and high periods for the serial clock (SCK) input are defined as follows:
Low: 2 CPU clock cycles for fck < 12 Mhz, 3 CPU clock cycles for fck >= 12 Mhz
High: 2 CPU clock cycles for fck < 12 Mhz, 3 CPU clock cycles for fck >= 12 Mhz
Which is saying the SCK low period needs to be at least 2 us and the high period needs to be at least 2 us. Each of these should be 4 us. You might hook up the scope to SCK and double check, however.
In other words, I don't think the SPI clock is the problem. Can you provide a simple schematic of how you have the Arduino wired-up to the target board?
-
-
I have a standard ICSP 2x3 connector on the rear of my enclosure. This ties to my SPI bus, which is in a master/slave setup.
My ATmega168's reset line is wired to the connector, whereas each slave devices' "SS" will use a programmed pin on the micro.
I used the suggested resistors in the recommended locations.
Every power pin in my entire design has a decoupling capacitor. My microcontroller has a 1uF and .1uF capacitor on each power pin for reassurance.
I'm operating at 5V and my voltage regulators can handle more than my requirements. The rails are fine under load.
There is an 8MHz oscillator for the micro, which was implemented based on their recommendations. Of course, this is disabled until I can change the fuse to enable it.
I have to be doing something wrong. I can't even burn the bootloader in the Arduino IDE or in AVRdude (cmd).
Is it worth getting a USB programmer for $20? I'm getting a little frustrated with this process. I know it'll be worth the effort later, though. I have an oscilloscope, but I don't know what the signals should look like at what times during the programming.
-
-
I don't know what the problem might be but someone else had problems trying to use that sketch as well so it might just be a bad sketch. I know they broke a lot of the old sketches when they went to version 1.0 too so that might be the problem.
So long as you have something like the attached schematic for the programming then I would give up and get a real programmer.
-
#23 Reply
Posted by
madworm
on 23 Jul, 2012 14:58
-
If you don't value your time, then by all means don't spend the huge amount of 20$ on a programmer that works.
-
#24 Reply
Posted by
MickM
on 23 Jul, 2012 21:33
-