Other Parts Discussed in Thread: CC2640, LAUNCHXL-CC2640R2
#include <xdc/runtime/Error.h> #include <ti/drivers/PIN.h> #include <ti/drivers/pin/PINCC26XX.h> #include <ti/devices/DeviceFamily.h> #include DeviceFamily_constructPath(inc/hw_prcm.h) #include DeviceFamily_constructPath(driverlib/sys_ctrl.h) #include <ti/sysbios/knl/Clock.h> #include <ti/drivers/Power.h> #include <ti/drivers/power/PowerCC26XX.h> #include <ti/sysbios/BIOS.h> #include <icall.h> #include "hal_assert.h" #include "bcomdef.h" #include "simple_peripheral.h" #include <inc/hw_memmap.h> #include <driverlib/vims.h> #ifndef USE_DEFAULT_USER_CFG #include "ble_user_config.h" // BLE user defined configuration icall_userCfg_t user0Cfg = BLE_USER_CFG; #endif // USE_DEFAULT_USER_CFG #include <ti/display/Display.h> /* Pin driver handles */ static PIN_Handle buttonPinHandle; static PIN_Handle ledPinHandle; /* Global memory storage for a PIN_Config table */ static PIN_State buttonPinState; static PIN_State ledPinState; /* Flag to store whether we woke up from shutdown or not */ bool isWakingFromShutdown; uint32_t currVal = 0; PIN_Config LedPinTable[] = { Board_PIN_LED0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially on */ PIN_TERMINATE /* Terminate list */ }; /* Led pin table used when waking from shutdown */ PIN_Config LedPinTableSd[] = { Board_PIN_LED0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ PIN_TERMINATE /* Terminate list */ }; /* Wake-up Button pin table */ PIN_Config ButtonTableWakeUp[] = { Board_PIN_BUTTON1 | PIN_INPUT_EN | PIN_PULLUP | PINCC26XX_WAKEUP_NEGEDGE, PIN_TERMINATE /* Terminate list */ }; /* Shutdown Button pin table */ PIN_Config ButtonTableShutdown[] = { Board_PIN_BUTTON1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE, PIN_TERMINATE /* Terminate list */ }; void buttonCallbackFxn(PIN_Handle handle, PIN_Id pinId) { CPUdelay(8000*100); if (!PIN_getInputValue(pinId)) { switch (pinId) { case Board_PIN_BUTTON1: PIN_setOutputValue(ledPinHandle, Board_PIN_LED0, 0); PINCC26XX_setWakeup(ButtonTableWakeUp); Power_shutdown(0, 0); break; } } } extern void AssertHandler(uint8 assertCause, uint8 assertSubcause); extern Display_Handle dispHandle; int main() { /* Register Application callback to trap asserts raised in the Stack */ RegisterAssertCback(AssertHandler); uint32_t rSrc = SysCtrlResetSourceGet(); Board_initGeneral(); if (rSrc == RSTSRC_WAKEUP_FROM_SHUTDOWN) { isWakingFromShutdown = true; ledPinHandle = PIN_open(&ledPinState, LedPinTableSd); // PIN_setOutputValue(ledPinHandle, Board_PIN_LED0, 1); /* Open LED pins */ buttonPinHandle = PIN_open(&buttonPinState, ButtonTableShutdown); PIN_registerIntCb(buttonPinHandle, &buttonCallbackFxn); } else { isWakingFromShutdown = false; ledPinHandle = PIN_open(&ledPinState, LedPinTable); PIN_setOutputValue(ledPinHandle, Board_PIN_LED0, 0); /* Configure DIO for wake up from shutdown */ PINCC26XX_setWakeup(ButtonTableWakeUp); /* Go to shutdown */ Power_shutdown(0, 0); } if (isWakingFromShutdown) { // Enable iCache prefetching PIN_setOutputValue(ledPinHandle, Board_PIN_LED0, 1); // Task_sleep(sleepUs / Clock_tickPeriod); PIN_setOutputValue(ledPinHandle, Board_PIN_LED0, 1); VIMSConfigure(VIMS_BASE, TRUE, TRUE); // Enable cache VIMSModeSet(VIMS_BASE, VIMS_MODE_ENABLED); #if !defined( POWER_SAVING ) /* Set constraints for Standby, powerdown and idle mode */ // PowerCC26XX_SB_DISALLOW may be redundant Power_setConstraint(PowerCC26XX_SB_DISALLOW); Power_setConstraint(PowerCC26XX_IDLE_PD_DISALLOW); #endif // POWER_SAVING /* Update User Configuration of the stack */ user0Cfg.appServiceInfo->timerTickPeriod = Clock_tickPeriod; user0Cfg.appServiceInfo->timerMaxMillisecond = ICall_getMaxMSecs(); /* Initialize ICall module */ ICall_init(); /* Start tasks of external images - Priority 5 */ ICall_createRemoteTasks(); SimplePeripheral_createTask(); } BIOS_start(); return 0; } void AssertHandler(uint8 assertCause, uint8 assertSubcause) { // Open the display if the app has not already done so if ( !dispHandle ) { dispHandle = Display_open(Display_Type_ANY, NULL); } Display_print0(dispHandle, 0, 0, ">>>STACK ASSERT"); // check the assert cause switch (assertCause) { case HAL_ASSERT_CAUSE_OUT_OF_MEMORY: Display_print0(dispHandle, 0, 0, "***ERROR***"); Display_print0(dispHandle, 2, 0, ">> OUT OF MEMORY!"); break; case HAL_ASSERT_CAUSE_INTERNAL_ERROR: // check the subcause if (assertSubcause == HAL_ASSERT_SUBCAUSE_FW_INERNAL_ERROR) { Display_print0(dispHandle, 0, 0, "***ERROR***"); Display_print0(dispHandle, 2, 0, ">> INTERNAL FW ERROR!"); } else { Display_print0(dispHandle, 0, 0, "***ERROR***"); Display_print0(dispHandle, 2, 0, ">> INTERNAL ERROR!"); } break; case HAL_ASSERT_CAUSE_ICALL_ABORT: Display_print0(dispHandle, 0, 0, "***ERROR***"); Display_print0(dispHandle, 2, 0, ">> ICALL ABORT!"); HAL_ASSERT_SPINLOCK; break; case HAL_ASSERT_CAUSE_ICALL_TIMEOUT: Display_print0(dispHandle, 0, 0, "***ERROR***"); Display_print0(dispHandle, 2, 0, ">> ICALL TIMEOUT!"); HAL_ASSERT_SPINLOCK; break; case HAL_ASSERT_CAUSE_WRONG_API_CALL: Display_print0(dispHandle, 0, 0, "***ERROR***"); Display_print0(dispHandle, 2, 0, ">> WRONG API CALL!"); HAL_ASSERT_SPINLOCK; break; default: Display_print0(dispHandle, 0, 0, "***ERROR***"); Display_print0(dispHandle, 2, 0, ">> DEFAULT SPINLOCK!"); HAL_ASSERT_SPINLOCK; } return; } void smallErrorHook(Error_Block *eb) { for (;;); }
I am trying to send the CC2640 module into Sleep mode, but facing the issue.
As the program is mentioned here, whenever the device gets started, it is already in power-saving mode unless the switch is pressed. at that time it is drawing 1mA current from.
However, when i turn on the circuit by pressing the button connected to pin number 0, the whole device gets starts and consumes about 5-6mA when the smartphone is not connected and when ble connect with smartphone bluetooth it consumes about 8-9mA current. But when I try to send it to power saving mode by pressing switch again it consumes 5mA but which is strange.
Please let me know if I am doing anything wrong here.