PreviousNext
iqrfSleep
Help > OS functions > Control > iqrfSleep

Function

 

Setting the TR module in power saving mode (Sleep)

Purpose

 

Easy and efficient power management. This function puts the TR into the Sleep mode.

Syntax

 

void iqrfSleep()

Parameters

 

  –           

Return value

 

  –

Output values

 

  –

Preconditions

 

     This function operates like the PIC machine instruction Sleep. Additionally, OS suspends all HW resources that are under its control (RF circuitry (RF IC is put into Sleep mode), timers, internal PIC pins, LEDs, etc.). The user should do the same for resources used by the application before entering the Sleep mode to achieve minimal power consumption.

     No PIC pins must be left as digital inputs without a defined input log. level values. See example E14-CONSUMPTION.

     Global interrupt enable (GIE) must not be disabled before iqrfSleep call.

     For wake-up on pin change, the required sequence should be executed. See the Example 2 below. Macro sleepWOC() can be used for this. Wake-up on pin change is default disabled.

     This function is not time-efficient for subsequent short sleep periods, especially if RF IC is off. For faster operation in such cases use sleep() instead but you should ensure minimal consumption by the user program. See Example 3.

Remarks

 

     IOCBF flag is cleared automatically by OS.

     Flags IOCBN and IOCBP are unchanged (not cleared) within iqrfSleep.

     Wake-up can be caused by power off/on, watchdog timeout, or on the C5 (for TR modules for SIM mounting, e.g. TR-72G) or Q12 (for SMT mounting, e.g.TR-76G) pin change.

     Wake-up takes about 1 ms.

     Wake-up types can be identified via the –TO and –PD status flags (in the MCU STATUS register).

Side effects

 

  –

See also

 

setRFsleep, iqrfDeepSleep, sleepWOC

Example 1

 

       // Minimize consumption (depends on resources used by the user)

Motor = 0;          // Stop the motor

ADON = 0;           // Disable A/D converter

SWDTEN = 0;         // Disable watchdog

iqrfSleep();       // Put the module into Sleep mode

Example 2

 

  // Wake-up on pin change. See Example E01-TX and IQRF-macros header file.

GIE = 0;                               // Disable all interrupts

writeToRAM(&IOCBN, IOCBN | 0x10);       // Negative edge enabled.

                                         // Instead of IOCBN.4=1; Bit IOCBN.4 cannot

                                         // be written directly due to OS restriction

IOCBP.4 = 1;                           // Positive edge enabled

IOCIE = 1;                             // Interrupt on change enabled

GIE = 1;                               // Global interrupt enabled

SWDTEN = 0;                            // Watchdog disabled

iqrfSleep();                           // Sleep

GIE = 0;

writeToRAM(&IOCBN, IOCBN & 0xEF);  // Negative edge disabled (Instead of IOCBN.4=0)

IOCBP.4 = 0;                           // Positive edge enabled

GIE = 1;                                // Global interrupt disabled

if (buttonPressed)                      // If button is pressed

  { ... }                              //   ...

Example 3

 

iqrfSleep();       // Sleep

  ...

  ...               // Wake-up, RF IC remains off

stopLEDR();         // Disable peripherals to minimize consumption

sleep();            // Faster (if RF IC is off). This is not an IQRF function

                    // but a machine instruction supported by C compiler.

pulseLEDR();       // Continue after wake-up