Go Down

Topic: How to tell if booting from reset or powerup? (Read 690 times) previous topic - next topic

dcb

Problem is that there is external equipment (LCD in this case) that really doesn't like getting double initialized once it is powerd up.  So you reporgram the duino or reset it or open a comm connection to it and the lcd goes haywire.  I have a temporary fix by powering the LCD controller with an arduino pin, but I want my pin back.  

So has anyone heard of a way to tell that a reset just occured and not a power up?

lilpunk1302

I'm pretty sure a Powerup and a Reset are the same thing as far as the ATMega's concerned.

Easiest solution I see would be to get a Programmer, and ditch the Arduino bootloader.

Then it won't pulse your pins when it powers up.

follower

Quote
So has anyone heard of a way to tell that a reset just occured and not a power up?

According to the ATmega168 data sheet (page 54) there is a register that tracks this: MCUSR - MCU Status Register

The MCUSR can differentiate between Power-on Reset and External Reset (among others).

Here's an Arduino-related use of the MCUSR: http://www.ladyada.net/library/arduino/bootloader.html

A hardware thought, could you hook the reset line to also trigger a LCD reset?

--Phil.

Adilson Akashi

Note that if you're using an Atmega8 instead of Atmega168, the register is MCUCSR (Atmega168 is MCUSR). And the page for the Atmega8 datasheet is 41.
PCB Designer

dcb

SWEET!!! Thanks guys!!  I will definately give that MCUSR a shot.  I saw a lot of stuff in the data sheet and couldn't quite make sense of all of it.  

dcb

Working good, thx again :)

Code: [Select]

void setup(){
 int po = MCUSR;
 MCUSR=0;
 pinMode (13,OUTPUT);
 if(po & 1)
   digitalWrite(13,HIGH); //or call lcd.init()
}
void loop(){}

follower

Quote
Code: [Select]
void setup(){
 int po = MCUSR;
 MCUSR=0;
 pinMode (13,OUTPUT);
 if(po & 1)
   digitalWrite(13,HIGH); //or call lcd.init()
}
void loop(){}

Thanks for completing the circle and posting your code. :)

Quote
Note that if you're using an Atmega8 instead of Atmega168, the register is MCUCSR (Atmega168 is MCUSR). And the page for the Atmega8 datasheet is 41.

Ditto for the ATmega128 which I had noticed.

--Phil.

Go Up