zigbee CC2530 series of tutorials 9 sleep wake experiment

Seeing all links courses:

zigbee CC2530 series of tutorials 0 Courses

Experiment 4.8 sleep wake

4.8.1 Purpose 

1. Study of the low-power control CC2530;

And timer interrupt wake of 2.CC2530.

4.8.2 Introductory Lecture

For unlimited long-distance transmission equipment, power consumption is a more critical technical indicators, and CC2530 ZigBee single-chip microcontroller based system has obvious advantages in low power consumption, leisure node module can go into sleep mode, the need to transfer data time to wake up, to further save power. This section presents the CC2530 2 Zhong wake-up method in sleep mode: external interrupts and timer wake.

Wake ZigBee nodes are two ways: a timer wake up and interrupt sleep timer is used to set the system to enter and exit the cycle between low-power sleep mode is also used when the system enters a low-power mode to maintain MAC timer (T2) of the timing. Having the following characteristics: timer counter 24 operating at the operating frequency of 32.768KHZ. 24 comparator with interrupt and DMA triggering PM2 running in low power mode.

1. interrupt wake-up

CC2530 primary register to be configured as follows: PCON, SLEEPCMD. Function shown in Table 4-7:

Table 4-7 CC2530 interrupt wake-sleep related control register

System power mode control register PCON (0x87)

Bit0

1

Forces the system into SLEEPCMD specified power mode, all interrupt signals can be

Clear this set.

0

 

The system power supply mode setting SLEEPCMD (0xBE)

 

Bit1: Bit0

00

Full-function mode

01

PM1

10

PM2

11

PM3

2. Timer wake

In addition to the wake-up timer register PCON, SLEEPCMD set, but also the timer count register ST0, ST1, ST2 is set, the specific features as described in Table 4-8:

Table 4-8 CC2530 wake-sleep timer mode control register associated

ST0(0x95)

Sleep counter data Bit7: Bit0

ST1(0x96)

Sleep counter data Bit15: Bit8

ST2 (0x97)

Sleep counter data Bit23: Bit16

The menu related registers described specifically as follows:

SLEEPCMD | = i; // set the system sleep mode, i = 0,1,2,3

PCON = 0x01; // goes into sleep mode, interrupted by an interrupt

PCON = 0x00; // wake up the system by interrupting interrupted

UINT32 sleepTimer = 0;

sleepTimer |= ST0;

sleepTimer |= (UINT32)ST1 << 8;

sleepTimer |= (UINT32)ST2 << 16;

sleepTimer + = ((UINT32) sec * (UINT32) 32768) // low speed oscillator;

ST2 = (UINT8)(sleepTimer >> 16);

ST1 = (UINT8)(sleepTimer >> 8);

ST0 = (UINT8) sleepTimer;

Specific procedures are as follows:

Interrupt wake-up program

#include <ioCC2530.h>

#define uint unsigned int

#define uchar unsigned char

//定义控制LED灯和按键的端口

#define LED2 P1_1 //定义LED2为P11口控制

#define KEY1 P0_4

//函数声明

void Delayms(uint); //延时函数

void InitLed(void);

void SysPowerMode(uchar sel);   //系统工作模式

/****************************

         延时函数

*****************************/

void Delayms(uint xms)   //i=xms 即延时i毫秒

{

 uint i,j;

 for(i=xms;i>0;i--)

   for(j=587;j>0;j--);

}

/****************************

//初始化程序

*****************************/

void InitLed(void)

{

P1DIR |= 0x02;  //P1_1定义为输出

LED2 = 1;    //LED2灯熄灭      

        P0INP  &= ~0X10;   //设置P0口输入电路模式为上拉/ 下拉

        P0IEN |= 0X10;     //P01设置为中断方式

        PICTL |= 0X10;     // 下降沿触发      

}

/****************************************************************

系统工作模式选择函数            

* para1  0  1 2 3          

* mode  PM0 PM1 PM2 PM3              

****************************************************************/

void SysPowerMode(uchar mode)

{

 uchar i,j;

 i = mode;

 if(mode<4)

 {  

     SLEEPCMD |= i;     // 设置系统睡眠模式

     for(j=0;j<4;j++);

     PCON = 0x01;         // 进入睡眠模式 ,通过中断打断

 }

 else

 {

     PCON = 0x00;             // 系统唤醒 ,通过中断打断

 }

}

/***************************

        主函数

***************************/

void main(void)

{   

    uchar count = 0;

InitLed(); //调用初始化函数     

    IEN1 |= 0X20;      // 开P0口总中断

    P0IFG |= 0x00;     //清中断标志

EA = 1;

        while(1)

        {

            LED2=~LED2;

            if(++count>=10)

            {

               count=0;

               SysPowerMode(3); //5次闪烁后进入睡眠状态PM3,等待按键S3中断唤醒

            }

            Delayms(500);

        }

}

/*****************************************

     中断处理函数-系统唤醒

*****************************************/

#pragma vector = P0INT_VECTOR

  __interrupt void P0_ISR(void)

 {

    if(P0IFG>0)

    {

       P0IFG = 0; //清标志位

    }

    P0IF = 0;

     SysPowerMode(4); //正常工作模式

 }

Timer wake-up program

#include <ioCC2530.h>

#define uint unsigned int

#define uchar unsigned char

#define UINT8 unsigned char

#define UINT32 long unsigned int

//定义控制 LED 灯和按键的端口

#define LED2 P1_1 //定义 LED2 为 P11口控制

#define KEY1 P0_4

//函数声明

void Delayms(uint xms); //延时函数

void InitLed(void); //初始化 P1 口

void SysPowerMode(uchar sel); //系统工作模式

/****************************

延时函数

*****************************/

void Delayms(uint xms) //i=xms 即延时 i 毫秒

{

    uint i,j;

    for(i=xms;i>0;i--)

    for(j=587;j>0;j--);

}/****************************

//初始化程序

*****************************/

void InitLed(void)

{

    P1DIR |= 0x02; //P1_1 定义为输出

    LED2 = 1; //LED2 灯熄灭

    P0INP &= ~0X10; //设置 P0 口输入电路模式为上拉/ 下拉

    P0IEN |= 0X10; //P01 设置为中断方式

    PICTL |= 0X10; // 下降沿触发

}

/***************************************************************

系统工作模式选择函数

* para1 0 1 2 3

* mode PM0 PM1 PM2 PM3

***************************************************************/

void SysPowerMode(uchar mode)

{

    uchar I,j;

    I = mode;

    if(mode<4)

    {

      SLEEPCMD |= I; // 设置系统睡眠模式

      for(j=0;j<4;j++);

      PCON = 0x01; // 进入睡眠模式 ,通过中断打断

    }

    else

    {

      PCON = 0x00; // 系统唤醒 ,通过中断打断

    }

}

/*****************************************

//初始化 Sleep Timer (设定后经过指定时间自行唤醒)

*****************************************/

void Init_SLEEP_TIMER(void)

{

    ST2 = 0X00;

    ST1 = 0X0F;

    ST0 = 0X0F;

    EA = 1; //开中断

    STIE = 1; //SleepTimerinterrupt enable

    STIF = 0; //SleepTimerinterrupt flag 还没处理的

}

/***************************************************************

设置睡眠时间

***************************************************************/

void Set_ST_Period(uint sec)

{

    UINT32 sleepTimer = 0;

    sleepTimer |= ST0;

    sleepTimer |= (UINT32)ST1 << 8;

    sleepTimer |= (UINT32)ST2 << 16;

    sleepTimer += ((UINT32)sec * (UINT32)32768);//低频晶振 PM2 模式

    ST2 = (UINT8)(sleepTimer >> 16);

    ST1 = (UINT8)(sleepTimer >> 8);

    ST0 = (UINT8) sleepTimer;

}/***************************

//主函数

***************************/

void main(void)

{

    uchar i;

    InitLed(); //调用初始化函数

    Init_SLEEP_TIMER(); //初始化 SLEEPTIMER

    while(1)

    {

        for(i=0;i<6;i++) //闪烁 3 下

        {

            LED2=~LED2;

            Delayms(200);

        }

        Set_ST_Period(3); //重新进入睡眠模式

        SysPowerMode(2); //进入 PM2 低频晶振模式

    }

}

//睡眠中断唤醒

#pragma vector = ST_VECTOR

__interrupt void ST_ISR(void)

{

    STIF = 0; //清标志位

    SysPowerMode(4); //进入正常工作模式

}

4.8.3 experimental results

Wake-interrupt mode, by pressing a key is generated external S3 (KEY1) wake-up interrupt, the D4 (LED2) 5 flashes to sleep, re-enter the working mode.

In timer awake mode, by setting a timer in a specific wake-up time, re-enter the operational mode, each wake-D4 (LED2) blinking 3.

Extended power management of knowledge --CC2530

Power Management Systems (works as follows):

1. The full-function mode, the high-frequency oscillator (16M or 32M) and a low frequency oscillator (32.768K RCOSC / XOSC)

All the work, the digital processing module is working properly.

2. PM1: a high frequency oscillator (16M or 32M) is closed, a low frequency oscillator (32.768K RCOSC / XOSC)

Work, digital core module is working properly.

3.PM2: low frequency oscillator (32.768K RCOSC / XOSC) work, digital core module shut down the system by RESET, external interrupt or wake-sleep counter overflows.

4. PM3: Crystal all closed, turn off the digital processing core module, the system can only be reset by RESET or external interrupts. The lowest power consumption in this mode.

发布了133 篇原创文章 · 获赞 51 · 访问量 20万+

Guess you like

Origin blog.csdn.net/aa120515692/article/details/104007071
Recommended