void WakeUpTimerInit(void) { /* TIMER CLK * * When in STOP or SLEEP mode, this timer is clocked by ALFCLK * ALFCLK is configured to be 1khz (1mS) * */ // PTB2 must be set to output B_GPIO_CTL = GPIO_CTL_PTB2_OUTPUT; // route Timer OC3 to PTB3 B_GPIO_OUT2_TCOMP3 = 1; // set Timer Ch3 to OC B_TIOS_IOS3 = 1; // force internal PTB3 to low B_TSCR1_TEN = 1; B_TCTL1 = 0x80; // set OC3 for Falling B_CFORC_FOC3 = 1; // force OC on OC3 B_TSCR1_TEN = 0; // setup a rising edge in 10s B_TCTL1 = 0xC0; // set OC3 for Rising B_TC3 = B_TCNT + 10000; // reload 10s B_TFLG1_C3F = 1; // Clear Irq Flag } void GoToSleep() { u8 CAN_status[3]; Sleep_CAN(CAN0, CMPTX); // request CAN channel 0 go to sleep with completing transmission scheduled do { Check_CAN_Status(CAN0,CAN_status); // read the channel 0 status }while (!(CAN_status[1]&SLPAK)); // wait till SLPAK bit set CAN_STDBY(STANDBYMODE); _DDRA.Bits.DDRA0 = 0; // Make STBY pin an input TsenseDisable(); VsenseDisable(); ADCLpEnable(); // Only monitor Current WakeUpTimerInit(); B_PCR_WUE = B_PCR_WUE_WUPTB4_MASK | B_PCR_WUE_WUPTB2_MASK; PCREnterStopMode();  // .....zzzzzzzzzzz (stop mode) // after wakeup the code continues to run here.... // but first the D2D Interrupt service routine will be run B_WD_CTL = WD_OFF; WakeUpReason = B_PCR_SR; B_PCR_SR = 0xFFFF; // Clear PCR Status Register Flags B_PCR_WUEH_WUPTB2 = 0; // Disable Wake Sources B_PCR_WUEH_WUPTB4 = 0; TsenseEnableExtSensor(); TsenseEnableIntSensor(); VsenseEnable(); CAN_STDBY(NORMALMODE); }