NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Programming via ICSP with SPI set as master

November 24, 2010
by esoderberg
esoderberg's Avatar

All,

I have been successfully programming my 168/328p chips via a 6 pin programmer, AVR studio, and the ICSP pins. The bootloader was been erased from these chips as it was not needed. I recently loaded code setting one of these chips as SPI Master.
Now I can no longer edit/load a new program on that chip, with the programmer sending back a variety of error messages, which I'm assuming is due to interference from the SPI on same pins. The same programmer and settings still work on other chips. Any work arounds or ideas?

Eric

November 24, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Eric,

When programming your chip via an ISP the reset line should be kept active (low). If your ISP programmer is doing its job correctly the reset line will be low when you turn it on so the program code should never even start running long enough to even configure the SPI module on. I'd check the reset line with a multimeter, when attempting to program, if it is indeed being dragged low by the ISP then I think the problem is not related to that chip being the master. Is there something in your circuit that might be keeping the reset line high for just your master chip?

Humberto

November 24, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Another thought. Is there is another chip in the circuit that is turning on and possibly driving the MISO line?

Humberto

November 24, 2010
by esoderberg
esoderberg's Avatar

Humberto,

There was another 328p set up as slave - I can still program that one - but I have disconnected that and everything else from the master chip at this point. I also tried connecting the reset line to ground, even though the programmer should be doing this.

Eric

November 25, 2010
by Rick_S
Rick_S's Avatar

I don't know if you are using a crystal with the chip or not, but if you are, you do need to leave that in place when programming.

Also, depending on your programmer, you may try adding a pullup resistor from vcc to pin 1 as well as the reset line of your programmer. This will allow the programmer full control of when to pull the reset low to keep the startup timings for programming.

This snippet is from the datasheet.

  1. Power-up sequence: Apply power between VCC and GND while RESET and SCK are set to “0”. In some systems, the programmer can not guarantee that SCK is held low during power-up. In this case, RESET must be given a positive pulse of at least two CPU clock cycles duration after SCK has been set to “0”.

Other than that, you aren't by any chance using the reset as an I/O pin and set the fuses that way did you? I know doing that will prevent an ISP programmer from working.

Rick

November 25, 2010
by mrobbins
(NerdKits Staff)

mrobbins's Avatar

Hi Eric,

I'm guessing that you also changed the target chip's fuse bits when you switched to using the ISP programmer. Do you have a record (i.e. in a Makefile) of what you set them to? There are definitely some fuse bit settings that will render a microcontroller no longer usable for ISP programming.

Also, you said that you get "a variety of error messages" -- care to post? Curious to know if avrdude is able to read the chip signature, etc.

Mike

November 25, 2010
by esoderberg
esoderberg's Avatar

Mike, Rick,

I was not accurate when I said nothing was connected to the chip in question. More precisely I have a 328p on a Nano v3.0, and one of your NK Atmega 168 chips in a duemilanove pcb, both of which I was able to program successfully for months via ICSP, but subsequent to loading the SPI code cannot. However, nothing else external to the pcb is connected to either at this point. As for the specific errors, they're all related to the fact that when the AVR STK500 and programmer try to enter programming mode it fails. I don't have a multi meter to use as Humberto suggested, but used an LED to see if reset was low, it appeared to be. I also tried a pull up per Rick, but no joy. Also, the AVR STK500 is unable to read the chips signature - returns a "signature does not match selected device" warning, which appears to be, again, because it can't enter programming mode.

As for the fuses, I certainly didn't do anything intentionally to change them beyond the programmer's default settings. However, you're probably right that this is the issue because on the AVR studio's programming Fuse menu,the SPIEN fuse is not checked as it is when the programmer is hooked up to my other 328p/168 chips that are working with the programmer. But I don't know if this is a cause or symptom of the fact that I can't get it to go into ISP mode and don't know how to change it (when I even open the AVR studio's Fuses page for programming AVR STK500 with 328p, it gives me an error because it fails to go into programming mode and I can't change the setting.) Below is the Makefile I used to create the hex file for upload via AVR studio.

GCCFLAGS=-g -Os -Wall -mmcu=atmega328p 
LINKFLAGS=-Wl,-u,vfprintf -lprintf_flt -Wl,-u,vfscanf -lscanf_flt -lm
LINKOBJECTS=../libnerdkits/delay.o ../libnerdkits/lcd.o ../libnerdkits/uart.o twimaster.o

Nunchuck.hex:   Nunchuck.c
    make -C ../libnerdkits
    avr-gcc ${GCCFLAGS} -o twimaster.o -c twimaster.c
    avr-gcc ${GCCFLAGS} ${LINKFLAGS} -o Nunchuck.o Nunchuck.c ${LINKOBJECTS}
    avr-objcopy -j .text -O ihex Nunchuck.o Nunchuck.hex

Nunchuck.ass:   Nunchuck.hex
    avr-objdump -S -d Nunchuck.o > Nunchuck.ass
November 25, 2010
by Ralphxyz
Ralphxyz's Avatar

Try using HVPP (High Voltage Parallel Programing) for seeing/setting your fuse settings. You can also use HVPP for programing.

Ralph

Post a Reply

Please log in to post a reply.

Did you know that an electroluminescent backlight for an LCD panel requires hundreds of volts AC to run? Learn more...