I tried to do make a sketch where my IR decoder sends some data while ESP8266 is in light sleep. Since IR header part is 8ms, if ESP8266 goes out of light sleep in less then that time, I could catch the rest of code. What I found is some weird inconsistency in the wifi_fpm_open / wifi_fpm_close pair.
When I initialize wifi_fpm_open in setup() and do only wifi_fpm_do_sleep in loop() function it appears that interrupts from IR code are somehow buffered and I get one more call after the whole sequence is over.
Code: Select all
extern "C" {
#include "user_interface.h" // this is for the RTC memory read/write functions
}
extern "C" {
#include "gpio.h"
}
const int DIGITAL_PIN = 15; // Digital pin to be read
const int RECV_PIN = 12; //an IR detector/demodulator is connected to GPIO pin 12
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println("Setup");
pinMode(RECV_PIN, INPUT );
pinMode(15, OUTPUT);
digitalWrite(15, LOW);
wifi_fpm_open();
wifi_fpm_set_sleep_type( LIGHT_SLEEP_T );
gpio_pin_wakeup_enable( GPIO_ID_PIN( RECV_PIN ), GPIO_PIN_INTR_LOLEVEL );
}
void loop()
{
int cnt, i;
cnt = wifi_fpm_do_sleep( 0xFFFFFFFF );
//wifi_fpm_close();
digitalWrite(15, HIGH);
delayMicroseconds(10);
digitalWrite(15, LOW);
if ( cnt ) Serial.println(cnt);
delay(50);
//wifi_fpm_open();
//wifi_fpm_set_sleep_type( LIGHT_SLEEP_T );
//gpio_pin_wakeup_enable( GPIO_ID_PIN( RECV_PIN ), GPIO_PIN_INTR_LOLEVEL );
}
If I try to wifi_fpm_close() the interrupt (after wake from light sleep) and try to setup the same parameters again at he end of he loop, it appears that during close/open calls, some spike goes to my IR line (I didn't send any IR code in the second case), interrupt is (somehow) buffered and I'm always waked up, so result is a 50ms oscillator.
Code: Select all
extern "C" {
#include "user_interface.h" // this is for the RTC memory read/write functions
}
extern "C" {
#include "gpio.h"
}
const int DIGITAL_PIN = 15; // Digital pin to be read
const int RECV_PIN = 12; //an IR detector/demodulator is connected to GPIO pin 12
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println("Setup");
pinMode(RECV_PIN, INPUT );
pinMode(15, OUTPUT);
digitalWrite(15, LOW);
wifi_fpm_open();
wifi_fpm_set_sleep_type( LIGHT_SLEEP_T );
gpio_pin_wakeup_enable( GPIO_ID_PIN( RECV_PIN ), GPIO_PIN_INTR_LOLEVEL );
}
void loop()
{
int cnt, i;
cnt = wifi_fpm_do_sleep( 0xFFFFFFFF );
wifi_fpm_close();
digitalWrite(15, HIGH);
delayMicroseconds(10);
digitalWrite(15, LOW);
if ( cnt ) Serial.println(cnt);
delay(50);
wifi_fpm_open();
wifi_fpm_set_sleep_type( LIGHT_SLEEP_T );
gpio_pin_wakeup_enable( GPIO_ID_PIN( RECV_PIN ), GPIO_PIN_INTR_LOLEVEL );
}
It would be nice to know what happens "under he hood" and why is this happening...
Best Regards, Bosko