On 4/5/06, Don AE5K <don@ae5k.us> wrote:
As a longtime user of micros (since the Intel 4004), I know about the
necessity of initializing the stack pointer in those devices which have it.
:) I used to work on 4004 systems.
However, some of the most recent Atmel datasheets (for example
doc2586.pdf, 2586F dated 4/06 on the tiny 25/45/85) lead me to believe
that Atmel has gone the way of initializing the stack pointer to the top
of SRAM at reset/powerup time. In this doc (2586F), paragraph 5.6.1
shows the "Initial Value" to be "RAMEND".
The smaller processors have hardware stack and can't be initted by the program.
On the larger ones, you must init the stack, and you're right you can set it anywhere you like.
This is great if true, BUT in the paragraph above it (par. 5.6) it says
"This Stack space in the data SRAM must be defined by the program before
any subroutine calls are executed or interrupts are enabled. The Stack
Pointer must be set to point above 0x60."
Actually, I'd set it SIGNIFICANTLY above 60, or you'll end up pushing data into the I/O with potentially hilarious consequences.
So the question is "Which is correct?" Is the stack pointer in these
newer devices initialized as shown so that the programmer does not need
to do the initialization?
If they've started preloading SP to the end of ram in the larger devices, that's news.
It's no big deal either way, four instructions that execute once isn't anything to worry about.--
Feel the power of the dark side! Atmel AVR