This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2530 sleep timer

Other Parts Discussed in Thread: CC2530

I have been trying for weeks now to try and put the CC2530 to sleep and wake it up using the sleep timer at regular intervals.

The sample codes that is provided by TI doesn't include a sleep function and the user guide doesn't explain things either.  I have configured some of the registers as below...

void main()

{....configure clocks etc

SLEEPCMD|=0X05; //power mode 1

/*load values into registers*/

while (STLOAD == 0);
 ST2=0X00;
ST1=0XFA;
ST0=0X00;

STIE=1;

EA=1;

PCON=0X01;//go to sleep

}

#pragma vector=ST_VECTOR

__interrupt void sleeptimer_int()

{

STIF = 0; //clear interrupt flag

/*load values again*/
while (STLOAD == 0);
ST2=0X00;
ST1=0XFA;
ST0=0X00;

}

It just doesn't seem to work. I've put a breakpoint at the sleep timer interrupt but it never goes there. Can someone please post a code snippet that simply puts the MCU to sleep and then wakes it up using the sleep timer interrupt at say 2sec? 

  • Please note that the debugger does not work in PM1. It works in PM2, so you can try that (note however that you will not get PM2 power consumption when in debug mode), or you can use a method to test the interrupt that does not involve the debugger, such as lighting an LED when waking up.

    Also note that the PCON = 1 instruction should be properly aligned in memory, see the user guide. The potential illegal alignment is not likely to be the cause of your problem, but it might give excessive power consumption in PM1.

  • even i am facing the same problem..can somebody help me? a simple example will be VERY VERY helpful.......

  • I changed it to  PM2 and included an LED toggle in the sleep timer, however it still gets stuck in the statement after PCON|=0x01. All i need is a continuous toggle of LEDs every 2sec.

  • #include <ioCC2530.h>

    //#define BV(x) (1 << (x))

    void Delay(){

    unsigned int k;
    for(k=0; k<65535; k++);
    }


    void SendChar1(unsigned char Get){

    U1DBUF=Get;
    while(!UTX1IF);
    UTX1IF = 0;

    }
    void Serial_Int()
    {



    CLKCONCMD=0x00;

    U0CSR |= 0x80; //UART mode selected for USART0.

    U1CSR |= 0x80; //UART mode selected for USART0.

    // U0UCR &= ~0x40; //H/w flow control disabled.

    PERCFG &= ~0x01; //Alernative 1 selected for UART0 peripheral.

    PERCFG |= 0x02; //Alernative 1 selected for UART0 peripheral.

    P0SEL |= 0x0C; //P0.2 and P0.3 peripheral mode enabled.

    P1SEL |= 0xF0; //P0.2 and P0.3 peripheral mode enabled.

    // P1SEL &= ~0xF0;

    U0GCR |= 0x08; U0BAUD = 0x3B; //Baud rate set to 9600 bps.


    U1GCR |= 0x08; U1BAUD = 0x3B; //Baud rate set to 9600 bps.


    }

    /***********************************************************************************
    * @fn port1_ISR
    *
    * @brief ISR framework for P0 digio interrupt
    *
    * @param none
    *
    * @return none
    */
    void HalKeyConfig();
    unsigned char i,j;
    int main (void)
    {




    i=0;
    j=0;
    union {
    unsigned char byte[2];
    unsigned short val;
    } t1cnt;

    // P1 = 0x00; // LEDs off
    P0DIR = 0x01;

    P1DIR = 0x00; // LEDs on P1_0 and P1_1 as output
    T1CTL = 0x00; //Disable Timer]
    T1CNTL = 0x00; //set the count value to 0

    // Start timer in free running mode, no prescaler
    T1CTL = 0x01;
    // P0_0=0;
    Delay();

    P0_0 =1;
    // Wait until timer is above period to use
    do {
    t1cnt.byte[0] = T1CNTL;
    t1cnt.byte[1] = T1CNTH;
    } while (t1cnt.val <= 0xA000);

    // Stop timer
    T1CTL = 0x00;
    //T1CNTL = 0x00; //set the count value to 0

    // Set period
    T1CC0L = 0x00;
    T1CC0H = 0xA0;

    T1CCTL0 = 0x44; // Interrupt on compare and compare mode
    T1OVFIM = 1; // Enable the overflow interrupt
    T1IE = 1; // Enable the Timer 1 interrupt
    EA = 1; // Global interrupt enable

    // Set prescaler to 128 and start timer in modulo mode
    T1CTL = 0x0E;
    HalKeyConfig();
    Serial_Int();
    SLEEPCMD = (SLEEPCMD & ~0x02) | 0x02;
    PCON = 1;

    while (1);
    }

    #pragma vector=T1_VECTOR
    __interrupt void t1Isr (void)
    {
    if (T1STAT & 0x01) {
    // Channel 0
    // P0_0 = ! P0_0; // Toggle the P1.0 LED (green on SmartRF05 EB) each period

    T1STAT = ~0x01;
    i++;
    j++;
    }
    if (T1STAT & 0x20) {
    // OVFIF
    P1_1 = ! P1_1; // Toggle the P1.1 LED (red on SmartRF05 EB) when overflow occurs
    T1STAT = ~0x20;
    }
    if(i>=2){
    i=0;
    P0_0 =0;

    Delay();

    P0_0 =1;

    SendChar1(SLEEPCMD);
    }


    if(j>=20){
    i=0;
    j=0;
    union {
    unsigned char byte[2];
    unsigned short val;
    } t1cnt;

    // P1 = 0x00; // LEDs off
    P0DIR = 0x01;

    P1DIR = 0x00; // LEDs on P1_0 and P1_1 as output
    T1CTL = 0x00; //Disable Timer]
    T1CNTL = 0x00; //set the count value to 0

    // Start timer in free running mode, no prescaler
    T1CTL = 0x01;
    // P0_0=0;
    Delay();

    P0_0 =1;
    // Wait until timer is above period to use
    do {
    t1cnt.byte[0] = T1CNTL;
    t1cnt.byte[1] = T1CNTH;
    } while (t1cnt.val <= 0xA000);

    // Stop timer
    T1CTL = 0x00;
    //T1CNTL = 0x00; //set the count value to 0

    // Set period
    T1CC0L = 0x00;
    T1CC0H = 0xA0;

    T1CCTL0 = 0x44; // Interrupt on compare and compare mode
    T1OVFIM = 1; // Enable the overflow interrupt
    T1IE = 1; // Enable the Timer 1 interrupt
    EA = 1; // Global interrupt enable

    // Set prescaler to 128 and start timer in modulo mode
    T1CTL = 0x0E;
    HalKeyConfig();
    SLEEPCMD = (SLEEPCMD & ~0x02) | 0x02;
    PCON = 1;
    }
    }


    #pragma vector=P1INT_VECTOR
    __interrupt void Port1(void)
    {

    P1IF=0;
    if(P1IFG){
    P0_0 = !P0_0;
    Delay();
    P1IFG=0;
    }

    }


    void HalKeyConfig()
    {
    // HAL_KEY_CLR_INT(); // Clear spurious ints.

    PICTL |= 0x10; // P1ICONL: Falling edge ints on pins 0-3.
    P1IEN |= 0x04; // Enable specific P1 bits for ints by bit mask.
    IEN2 |= 0x10; // Enable general P1 interrupts.

    }

    copy paste above code ,,  at start up controller is in Sleep Mode ,,, when u give interrupt to P1_2 ,low to high ,,, controller starts blinking for 5 sec and then again goes to 

    sleep mode second time it doesnt wake up even after interrupt 

    i have checked its current which is 9mA , in sleepmode and 17 mA in active mode ,,, but according to datasheet it should be 1uA ,,can anyone tell me the reason for such huge change ,,,i will thank full if some one tell my mistakes thanks

    in advance

  • Woking Fine Sleep Timer Interrupt CC2530

    Controller Wakes Up every 5 second and then Sleep

    in sleep mode current is 1uA

    in wake up mode Current is 15mA

    #include <ioCC2530.h>

    unsigned char volatile __xdata *ptr;
    unsigned char firstbyte[8];
    void Delay(){

    unsigned int k;
    for(k=0; k<65535; k++);
    }


    void SendChar1(unsigned char Get){

    U1DBUF=Get;
    while(!UTX1IF);
    UTX1IF = 0;

    }

    void Serial_Int()
    {



    CLKCONCMD=0x00;

    U0CSR |= 0x80; //UART mode selected for USART0.

    U1CSR |= 0x80; //UART mode selected for USART0.

    // U0UCR &= ~0x40; //H/w flow control disabled.

    PERCFG &= ~0x01; //Alernative 1 selected for UART0 peripheral.

    PERCFG |= 0x02; //Alernative 1 selected for UART0 peripheral.

    P0SEL |= 0x0C; //P0.2 and P0.3 peripheral mode enabled.

    P1SEL |= 0xF0; //P0.2 and P0.3 peripheral mode enabled.

    // P1SEL &= ~0xF0;

    U0GCR |= 0x08; U0BAUD = 0x3B; //Baud rate set to 9600 bps.


    U1GCR |= 0x08; U1BAUD = 0x3B; //Baud rate set to 9600 bps.


    }


    static void SleepTimerInit(void);
    unsigned char i,j;
    int main (void)
    {



    P0DIR=0x03;
    i=0;
    j=0;

    P0_0=0;
    P0_1=0;
    Serial_Int();

    SleepTimerInit();


    SLEEPCMD |= 0x06; // Setting power mode 2
    PCON |= 0x01; // Enable power mode

    while (1){

    Delay();
    P0_0=0;

    Delay();
    Delay();
    Delay();

    Delay();
    Delay();
    Delay();
    P0_0=1;


    PCON |= 0x01; // Enable power mode

    }



    }


    static void SleepTimerInit(void)
    {

    unsigned long sleeptime = 0;

    sleeptime |= ST0;
    sleeptime |= (unsigned long)ST1 << 8;
    sleeptime |= (unsigned long)ST2 << 16;


    sleeptime += ((unsigned long)5 * (unsigned long)32753);

    /* set sleep timer */
    while((STLOAD & 0x01) == 0); // wait before ST0. STLOAD.LDRDY is 0 during the load
    ST2 = (unsigned char)(sleeptime >> 16);
    ST1 = (unsigned char)(sleeptime >> 8);
    ST0 = (unsigned char) sleeptime;
    STIE=1;


    // IRCON |= 0x80;
    IEN0 |= 0x20;
    EA = 1; // Enable global interrupt

    PCON=0X01;//go to sleep
    }


    #pragma vector=ST_VECTOR

    __interrupt void sleeptimer_int()

    {

    unsigned long sleeptime = 0;
    STIF = 0; //clear interrupt flag



    sleeptime |= ST0;
    sleeptime |= (unsigned long)ST1 << 8;
    sleeptime |= (unsigned long)ST2 << 16;


    sleeptime += ((unsigned long)10 * (unsigned long)32753);

    /* set sleep timer */
    while((STLOAD & 0x01) == 0); // wait before ST0. STLOAD.LDRDY is 0 during the load
    ST2 = (unsigned char)(sleeptime >> 16);
    ST1 = (unsigned char)(sleeptime >> 8);
    ST0 = (unsigned char) sleeptime;

    P0_0=0;

    Delay();
    P0_0=1;

    Delay();
    Delay();
    Delay();

    }