Hi,
I am trying to get my arduino wake up the moment it receives serial communication. I am not concerned about losing serial messages during the "wake up" process though...
I think I got the concept right, but since I am new to electronics, I am pretty sure this is a dumb circuit issue...
My objective is to make sure that INT0 receives the RX signal (LOW) only when the IS_AWAKE signal (see fig) is HIGH; effectively we would like to get interrupted by serial
communication ONLY when arduino is sleeping. In this way, we can use INT0 for another purpose when arduino is awake.
Now, if I directly connect RX & the INT0 pin, my interrupt routine works flawlessely. However, when I implement the shown schematic, I see that the LED blinks whenever I
receive serial IO, but the interrupt doesn't get triggered. I tried all sorts of techniques... pull-ups, pull-downs etc but I couldn't figure out whats going on here.
Why does the LED blink successfully when I don't see the interrupt? Am I missing something here? How should I change the circuit so that I can wake up arduino through serial communication and interrupts that trigger only when arduino is asleep?
and my code...
#include <Stepper.h>
#include <avr/sleep.h>
#include <avr/power.h>
#define INT0_PIN 0
#define INT0 2
#define awakePin 10
#define enable_ELE 11
#define enable_AZ 12
#define rs485_cnt 13
#define LISTEN LOW
#define COMMAND HIGH
typedef struct numStruct {
int a;
int b;
} num;
void initPins();
void wakeUpNow();
void sleepNow();
int sleepStatus = 0; // variable to store a request for sleep
int count = 0; // counter
volatile int status=3;
void setup() {
initPins();
Serial.begin(9600);
digitalWrite(awakePin, HIGH);
digitalWrite(rs485_cnt, LOW);
}
void loop() {
int sb=0;
int flag=0;
char pp=0;
num angles;
if (status<=0) {
status=0;
sleepNow();
}
if (status>0) {
status--;
delay(300);
digitalWrite(awakePin, LOW);
delay(300);
digitalWrite(awakePin, HIGH); // wakeUpNow when pin 2 gets LOW+
}
}
void initPins()
{
// pinMode(0, INPUT);
pinMode(1, OUTPUT);
//pinMode(2, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
digitalWrite(1, LOW);
//digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(rs485_cnt, LOW);
//pinMode(INT0, INPUT);
}
void wakeUpNow() // here the interrupt is handled after wakeup
{
detachInterrupt(0); // My board seems to be hanging if this is not there.... did I screw up something?
// wakeUpNow code will not be executed
status=5;
}
void sleepNow() // here we put the arduino to sleep
{
digitalWrite(awakePin, LOW);
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
sleep_enable();
power_adc_disable();
power_spi_disable();
power_timer0_disable();
power_timer1_disable();
power_timer2_disable();
power_twi_disable();
attachInterrupt(INT0_PIN, wakeUpNow, LOW); // use interrupt 0 (pin 2) and run function
// wakeUpNow when pin 2 gets LOW
sleep_mode(); // here the device is actually put to sleep!!
// THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
sleep_disable(); // first thing after waking from sleep:
// disable sleep...
//
power_all_enable();
digitalWrite(awakePin, HIGH);
delay(100);
Serial.flush();
}
Any comments/suggestions are highly appreciated.