Sleep and hibernate on GPRS

From openPicus Wiki
Jump to: navigation, search

Contents

What you are going to learn

This tutorial shows how to use Power Saving Modes on Flyport and FlyportPRO GPRS.

Introduction to Sleep, Hibernate and Low Power Mode

Flyport GPRS has three type of Power Saving modes:

  • Enable Low Power Mode of GPRS transceiver (Low Power mode)
  • Turn OFF GPRS transceiver only (Hibernation mode) - NOTE: this function is not suggested when your application needs to wake up more often than once a hour.
  • Turn OFF GPRS transceiver and put in Sleep state microcontroller (Sleep mode) - NOTE: this function is not suggested when your application needs to wake up more often than once a hour.

Hibernation and Low Power permits to use all the Hardware features of Flyport module, but all connectivity functions with GPRS module will be ignored. Using Sleep mode only external interrupts and RTCC can wake up microcontroller. In Low Power Mode, Flyport GPRS remains connected to GSM network, so GPRS modem can receive Voice Calls and SMSs, but such conditions will wake up GPRS Modem.

NOTE

Sleep mode deactivates both transceiver and Microcontroller. When Flyport go out from Sleep condition, only Microcontroller is turned on. Flyport Firmware will continue from the same position it was interrupted, just like a pause.

How to use it

On Serial Monitor utility of IDE you can command Flyport GPRS to switch between Hibernate, Sleep, Low Power and On state. Type those different commands using a Serial Monitor and press ENTER to send them:

  • hibernate (NOTE: don't use this function if your application needs to wake up more often than daily)
  • sleep (NOTE: don't use this function if your application needs to wake up more often than daily)
  • lowPower
  • gsmOn

Flyport PRO

When the Sleep Mode is activated, the ENVREF pin (which enables the VREF diode) is not switched off automatically. If the lowest possible consumption is wanted, this pin must be switched off with the simple following code before GSMSleep:

ADCRefEnable(FALSE);

Now, the VREF diode is powered off and no current flows through it.

Remember: after waking up, the ENVREF must be switched on manually if you want to use the internal ADC or similar.
Line code to do it

ADCRefEnable(TRUE);

Pinout and hardware configuration

In the following tutorial, one external interrupt is configured to wake up Flyport from Sleep condition with the pressure of a button. Flyport modules can also be awaken using RTCC timed alarms. A button between p7 and GND should be placed to raise External Interrupt (or connect with a wire p7 and GND signal...).

Flyport GPRS

In case you are using Flyport GPRS (not FlyportPRO), you should make the following modifications on code example:

  • replace p31 (used as led output) with p21
  • remove the ADCDetach(3) statement, since p7 is already a digital IO in Flyport GPRS module and Analog 3 is located at p20 and not p7

Code example


The functions used in this tutorial are the following:

Name Function Description
 void GSMHibernate() Starts the "turn OFF" procedure of GSM Module
 void GSMSleep() Executes "turn OFF" procedure of GSM Module, and (when done) PIC microcontroller in sleep mode
 void GSMLowPowerEnable() Turns GSM module in Low Power Mode, can be awaken using gsmOn, SMSs or Voice Calls (microcontroller is active)
 void GSMOn() Turns GSM module ON after hibernation or sleep, restoring defaults parameters


Source code for taskFlyport.c:

#include "taskFlyport.h"
 
void external_interrupt_function()
{ 
    // Reset interrupt 
    INTDisable(2);
    UARTWrite(1,"Wakeup!\r\n");
    IOPut(p31, on);
    INTEnable(2);
}
 
char inBuff[50];
 
void FlyportTask()
{
    // Set external interrupt
    ADCDetach(3);
    IOInit(p7,inup); // Tie to ground for interrupt execution...
    IOInit(p7, EXT_INT2);
    INTInit(2, external_interrupt_function, 1);
    INTEnable(2);
 
    vTaskDelay(20);
    _dbgwrite("Flyport Task Started...\r\n");
    IOInit(p31, out);
 
    // Wait for GSM Connection successfull
    _dbgwrite("Waiting network connection...");
    while((LastConnStatus() != REG_SUCCESS) && (LastConnStatus() != ROAMING))
    {
        vTaskDelay(20);
        IOPut(p31, toggle);
        do
        {
            UpdateConnStatus();
            while(LastExecStat() == OP_EXECUTION)
                vTaskDelay(1);
        }while(LastExecStat() != OP_SUCCESS);
    }
    vTaskDelay(20);
    IOPut(p31, on);
    _dbgwrite("Flyport registered on network!\r\n");
 
    _dbgwrite("Flyport GPRS Power saving modes tutorial example!\r\n");
    while(1)
    {
        if(UARTBufferSize(1) > 0)
        {
            vTaskDelay(20);
            int len = UARTBufferSize(1);
            if(len > 49)
                len = 49;
            UARTRead(1, inBuff, len);
            inBuff[len+1] = '\0';
 
            // Hibernation: Turns OFF GPRS Module, but Microcontroller is running
            if(strstr(inBuff, "hibernate")!= NULL)
            {
                _dbgwrite("Starting Hibernate...\n");
 
                // Force turn off LEDs to reduce power consuption
                IOPut(p31, off);
 
                GSMHibernate();
 
                // This instruction waits for function end...
                while(LastExecStat() == OP_EXECUTION)
                {
                    vTaskDelay(1);
                }
                // This instruction checks the result of operation
                if(LastExecStat() == OP_SUCCESS)
                    _dbgwrite("Hibernation done!\n");
                else
                    _dbgwrite("Problems on hibernation...\n");    
            }
            // Sleep: Turns OFF GPRS Module, and puts Microcontroller in sleep (it can be awake with external interrupt)
            // Please remember to turn ON again GPRS Module after a wake up to use GPRS functions...
            else if(strstr(inBuff, "sleep")!=NULL)
            {
                _dbgwrite("Entering sleep mode...\n");
 
                // Force turn off LEDs to reduce power consuption
                IOPut(p31, off);
 
                GSMSleep();
 
                while(LastExecStat() == OP_EXECUTION)
                {
                    vTaskDelay(1);
                }
 
                vTaskDelay(25);
 
                // This instruction checks the result of operation
                if(LastExecStat() == OP_SUCCESS)
                    _dbgwrite("Sleep done!\n");    
                else
                    _dbgwrite("Failed...\n");
            }
 
            else if(strstr(inBuff, "lowPower")!=NULL)
            {
                _dbgwrite("Entering low power mode...\n");
 
                IOPut(p31, off);
 
                GSMLowPowerEnable();
 
                while(LastExecStat() == OP_EXECUTION)
                {
                    vTaskDelay(1);
                }
 
                vTaskDelay(25);
 
                if(LastExecStat() == OP_SUCCESS)
                {
                    _dbgwrite("Low Power Mode Enabled!\n");
                    _dbgwrite("Try to send a SMS to your Flyport and lets see it wakes up!\n");
                }
                else
                    _dbgwrite("Failed!\n");
            }
 
            // GSM On: Turns ON GPRS Module, and initialize it with default parameters
            else if(strstr(inBuff, "gsmOn")!=NULL)
            {
                _dbgwrite("Turning on GSM from sleep/hibernation...\n");
 
                GSMOn();
 
 
                // This instruction waits for function end...
                while(LastExecStat() == OP_EXECUTION)
                {
                    vTaskDelay(1);
                }
 
                // This instruction checks the result of operation
                if(LastExecStat() == OP_SUCCESS)
                    _dbgwrite("GSM turned ON!\n");
                else
                    _dbgwrite("Problems on GSM turn on...\n");
            }
        }
    }
}
Personal tools
Namespaces

Variants
Actions
START HERE
DEVELOPMENT
HARDWARE INFO
RESOURCES
PHASED OUT
Toolbox