Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

initial flash programming run versus subsequent runs

2013-12-13 by Steven Hodge

I have something weird going on, where a small part of the code only works
when the code is first uploaded to flash memory, and does not work when
subsequently the power to the uC is cycled on/off.

The code is assembly, for a Mega644P.  Programming is done using a JTAG
interface and AVR Dragon. 

Briefly, the code monitors a set of switches and whenever a switch changes
state it sends a single byte message out a serial port.  The code is
interrupt-driven and uses the port pin change interrupts.  The USART actions
are also interrupt-driven, using code that has supposedly stood the
proverbial test of time.

At the end of the initialization code, after all the port interrupts and
pins have been set up, there are 3 steps:

-- initialize the USART
-- enable global interrupts with "sei" (necessary for the next step)
-- send a single, unique byte (0x7F) out the serial port.  This is intended
as a "wake-up/I'm alive" message to the receiving end.

The code then enters a sleep loop, waiting for switch changes.

When I initially upload the program to flash memory, all the above works
perfectly, just as I want it to.  I get the wake-up byte and whenever a
switch changes state I get a byte, one for turning on, one for turning off.
However, if I then cycle the power off/on, I do NOT get the wake-up byte but
the board still faithfully and reliably sends out switch change bytes from
the main sleep loop.  So the "meat" of the program works fine, always.  It's
just the wake-up byte that doesn't.  This is the same result whether or not
I have the JTAG programming connection plugged in or not.  I have also tried
a JTAGICE3 programmer (still using JTAG) and the result is the same.

And, of course, the Catch-22 is that I can't use the debugger part of the
JTAG connection to debug this because every time I enter debugging mode it
uploads the program once again to flash memory and thus, as expected, it
works perfectly and transmits the wake-up byte just fine.  

The serial-to-USB adapter that I use has led's on the TX/RX lines and, sure
enough, I see nothing when the wake-up byte should be, but isn't,
transmitted.  So I know the issue is not with the receiving end.  It's
something to do with the uC end.

I'd be happy to upload the code, but first I'm asking if anyone has had
similar things happen and/or know what might be a difference between initial
code upload and subsequent re-starts.  

Thanks in advance,

Steve

PS.  I'm also going to post this on AVR-Freaks, so you can ignore it if you
see it there.

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.