Pages: [1]   Go Down
Author Topic: How to tell if booting from reset or powerup?  (Read 606 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
God Member
*****
Karma: 1
Posts: 513
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Vancouver, BC, Canada
Offline Offline
Full Member
***
Karma: 0
Posts: 164
Arduino 4 Prez
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

New Zealand
Offline Offline
God Member
*****
Karma: 0
Posts: 999
Arduino pebbles
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Brazil
Offline Offline
Sr. Member
****
Karma: 0
Posts: 443
..., to learn, to know, to make, to share, to l...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

PCB Designer

0
Offline Offline
God Member
*****
Karma: 1
Posts: 513
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  
Logged

0
Offline Offline
God Member
*****
Karma: 1
Posts: 513
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Working good, thx again smiley

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

New Zealand
Offline Offline
God Member
*****
Karma: 0
Posts: 999
Arduino pebbles
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Code:
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. smiley

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.
Logged

Pages: [1]   Go Up
Jump to: