--- In AVR-Chat@yahoogroups.com, "Frank" <transistortoaster@...> wrote:
> How does the AVR (say atmega16) know the difference if it is going to
> get programmed or if it is going to run the user program?
It doesn't, it always begins running the code to which the reset
vector points upon any reset.
For SPI programming, the device is held in reset during programming
thus preventing it from running the existing program. I don't know
the JTAG protocol but I suspect that there is a sequence of signals
that causes the device to enter some special mode during which
programming occurs.
> Also can I get away with only a JTAG cable for programming and
> debugging, assuming that the part is fresh from factory?
Many, perhaps most/all, AVRs that support JTAG have their JTAG
enabling fuses programmed by default. Check the datasheet for your
device to be sure.
If you're planning to use JTAG for your In System Programming, you'll
find that those four I/O lines can't be used for anything else. If,
on the othe rhand, you choose SPI for ISP needs you can use the SPI
lines for other purposes - you just have to be certain that you
prevent your peripheral circuitry from driving the MOSI/MISO/SCK lines
when reset is asserted.
Don Kinzer
ZBasic Microcontrollers
http://www.zbasic.net