Other Parts Discussed in Thread: CC2544, CC2545
Hi,
I'm testing power consumption of CC2543 in power mode PM2 with sample code from TI , i found that:
- As data sheet say that about CC2543, Power mode 2 (sleep timer on): current consumption 0.9 μA,
- I have use sleep time 30 seconds in PM2. but still no decreasing the current consumption <30 μA
-Please check the code and let me know where is problem?
#include <power_mode.h>
#include <hal_types.h>
#include <hal_wait.h>
#include <ioCC254x_bitdef.h>
#include "ioCC2543.h"
/***********************************************************************************
* LOCAL VARIABLES
*/
// Union for storing 24 bit sleep timer value.
typedef union {
unsigned long value;
unsigned char byte[4];
} union_32bit;
static union_32bit sleep_timer;
/***********************************************************************************
* LOCAL FUNCTIONS
*/
/***********************************************************************************
* @fn sleep_isr
*
* @brief Interrupt service routine for the sleep timer which wakes the
* system from Power Mode. When awake the flags are cleared and
* LED1 is toggled.
*
* @param void
*
* @return void
*/
#pragma vector = ST_VECTOR
__interrupt void sleep_isr(void)
{
/* Note that the order in which the following flags are cleared is important.
For pulse or egde triggered interrupts one has to clear the CPU interrupt
flag prior to clearing the module interrupt flag. */
// Toggle SRF05EB LED1.
P1_0 ^= 1;
// Clear [IRCON.STIF] (Sleep Timer CPU interrupt flag).
STIF = 0;
}
/***********************************************************************************
* @fn main
*
* @brief Setup Sleep Timer and Sleep Timer interrupt. Goes in and out of
* Power Mode 1.
*
* @param void
*
* @return 0
*/
int main(void)
{
/***************************************************************************
* Setup clock & frequency
*
* The system clock source used is the HS XOSC at 32 MHz speed.
*/
// Change the system clock source to HS XOSC and set the clock speed to 32 MHz.
CLKCONCMD = (CLKCONCMD & ~(CLKCON_CLKSPD | CLKCON_OSC)) | CLKCON_CLKSPD_32M;
// Wait until system clock source has changed to HS XOSC (CLKCON.OSC = 0).
while(CLKCONSTA & CLKCON_OSC);
// We need to wait approx. 2 ms until the 32 kHz RCOSC is calibrated.
halMcuWaitMs(2); // Given 32 MHz system clock source.
/***************************************************************************
* Setup I/O
*/
/*
// Initialize P1_0 for SRF05EB LED1.
P1SEL &= ~BIT0; // Function as General Purpose I/O.
P1_0 = 1; // LED1 on.
P1DIR |= BIT0; // Output.
*/
/***************************************************************************
* Setup Sleep Timer interrupt
*/
// Clear [IRCON.STIF] (Sleep Timer CPU interrupt flag).
STIF = 0;
// Set the individual, interrupt enable bit [IEN0.STIE=1].
STIE = 1;
// Enable global interrupt by setting the [IEN0.EA=1].
EA = 1;
/***************************************************************************
* Setup Power Mode in PM2.
* Power Mode 2 is typically used when sleep time exceeds 3 ms.
* The CC2544 does not support PM2 and PM3!
*/
// Set power mode, PM2.
SLEEPCMD = (SLEEPCMD & ~SLEEPCMD_MODE) | SLEEPCMD_MODE_PM2;
/***************************************************************************
* Setup Sleep Timer
*
* The Sleep Timer is running on the 32 kHz RC oscillator. The CC2545 has
* the possibility of using an external 32 kHz crystal, the LS XOSC can be
* selected by clearing the CLKCONCMD.OSC32K bit. This initiates a clock
* source change, CLKCONSTA.OSC32K reflects the current setting. Note this
* must be done while the system clock source is HS RCOSC.
*/
// To ensure an updated value is read, wait for a positive transition on the
// 32 kHz clock by polling the SLEEPSTA.CLK32K bit.
while(!(SLEEPSTA & SLEEPSTA_CLK32K)); // Wait for positive flank on sleep timer.
// Read the sleep timer current value.
sleep_timer.byte[0] = ST0; // ST0 must be read first.
sleep_timer.byte[1] = ST1;
sleep_timer.byte[2] = ST2;
sleep_timer.value = 0;
while(1)
{
// Increment the Sleep Timer value with 32753 cycles to create a new
// compare match in approx. 1 second.
sleep_timer.value += 327530;
// When loading a new compare value for the Sleep Timer,
// the ST2 and ST1 registers must be loaded before ST0.
ST2 = sleep_timer.byte[2];
ST1 = sleep_timer.byte[1];
// Wait until load ready, before writing to STO.
while( !(STLOAD & STLOAD_LDRDY) );
ST0 = sleep_timer.byte[0];
//PCON = 0x01;
// Force the device to enter the power mode set by SLEEPCMD.MODE.
//LLECTRL = 0x00; //it is recommended to set LLECTRL to 0 before entering PM2/PM3
EnterSleepModeProcessInterruptsOnWakeup();
//LLECTRL = 0x01;//set it back to 1 after returning from PM2/PM3
sleep_timer.value = 0;
}
}