Reset caused by stack pointer SP not setup

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hello:

I just spent a few hours tracking a tricky rascal...My program is pretty simple reading & writing to ports A & B of a tiny26. I am also using the PWM & A/D & an ISR timer. All seemed to work well, after figuring out how to set up all the control bits. But Port PB4 was refusing to work 100% properly. Port A was just fine. Since PB4 is shared with other functions, such as external xtal & interupt on pin change, I looked to see if the pin had been "redefined".

one thing I noticed was that port A was being written "directly" -- that is different values are being directly written to port A, while port B used the IN function to read the port, then some processing was done on the value & it was spit back out.

After much messing around I realized that the processor was constantly being reset, so port B was being accidentally reinitialized. I looked at all sources of what might cause the reset. The rest pin itself showed no pulses on a scope. I tried putting in watchdog timer reset instructions here & there to no avail (tho I didn't think I had set up the WDT in the first place).

read the manual & of course it was no help either!

Then it dawned on me that the reinitialization seemed to be syncd up with my ISR timer (few hundred ms). Of course I had properly pushed and popped the status register in the ISR. THEN IT HIT ME....I never initialized the stack pointer!!! So somehow this was causing the problem (though I'm not sure what I was writing over).
The FIX :
ldi r16, RAMEND
out SP, r16 ; THAT'S IT--a few hours aggrevation saved for you

now, I could use a quick bit of help...what is the shortest code to toggle a bit on one port (say PA5)
is there anything shorter than the following????
in temp, porta
ldi temp2, $20
eor temp, temp2
out porta, temp

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try

https://www.avrfreaks.net/phpBB2/...

Aren’t searches great

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

in temp, porta
ldi temp2, $20
eor temp, temp2
out porta, temp

On newer devices (mega169, megaX8, tiny2313, tiny13) you can toggle the bits in PORTn by writing 1's to the corresponding bits in PINn. But AFAIK, that's the best way to toggle a pin on the tiny26, which doesnt have the toggling feature.

There could be a way toggle the pin without needing an extra register for the bitmask. I don't see how you could do it in the same number of instructions though.. it would take longer.

/* John Butera */