lpcware

lpc1788 can bus wakeup problem

Discussion created by lpcware Employee on Jun 15, 2016
Content originally posted in LPCWare by sipiyou on Thu May 15 05:18:59 MST 2014
Dear All,

I got a small issue with the wakeup.

This is the the relevant part of the code. It does not matter what sleep mode I use, the cpu will not wakeup properly. Can someone tell me what I am doing wrong ?! the can-bus part works fine on both channels on regular operation.

void myinit_can (void) {
    PINSEL_ConfigPin (0, 0, 1); // CAN-RD P0.0
    PINSEL_ConfigPin (0, 1, 1); // CAN-TX P0.1

    PINSEL_ConfigPin (0, 2, 1); // U0-TXD
    PINSEL_ConfigPin (0, 3, 1); // U0-RXD

    PINSEL_ConfigPin (2, 7, 1); // CAN-RD2 P2.7
    PINSEL_ConfigPin (2, 8, 1); // CAN-TX2 P2.8

    CAN_Init (CAN_ID_1, 500000);
    CAN_Init (CAN_ID_2, 500000);

    CAN_IRQCmd (CAN_ID_1, CANINT_RIE, ENABLE);
    CAN_IRQCmd (CAN_ID_2, CANINT_RIE, ENABLE);
    CAN_SetAFMode (CAN_ACC_BP);

    NVIC_EnableIRQ (CAN_IRQn);
    NVIC_EnableIRQ (CANActivity_IRQn);       /* enable CAN activity interrupt */
}


void CANActivity_IRQHandler (void) {
    canactflag = 1;
    LPC_SC->CANSLEEPCLR = CAN1SLEEPCLR | CAN2SLEEPCLR;
    LPC_CAN1->MOD =
LPC_CAN2->MOD &= ~ CAN_MOD_SM;
    LPC_SC->CANWAKEFLAGS = CAN_WAKEFLAGES_CAN1WAKE | CAN_WAKEFLAGES_CAN2WAKE;
}

int main(void) {
startup:

    SystemInit();
    led_status (LED_INIT);

#ifdef DEBUG_ON
    myinit_uart();

    d_printf_P ("speed: %ld\n", CLKPWR_GetCLK(CLKPWR_CLKTYPE_CPU));
    d_printf_P ("\nTimeStart:%ld\n", SysTickCnt);
#endif


    myinit_can();
    init_timer();

    led_status (LED_ON);

#ifdef DEBUG_ON 
    d_printf_P ("speed: %ld\n", CLKPWR_GetCLK(CLKPWR_CLKTYPE_CPU));
    d_printf_P ("\nTimeStart:%ld\n", SysTickCnt);
#endif

    StartTime = SysTickCnt;
    canactflag = 0;

    while (1) {
if (canactflag) {
    canactflag = 0;
    can_sleep = 0;
    goto startup;
/*
    SystemInit();
    led_status (LED_INIT);
    myinit_uart();
    init_timer();
    StartTime = SysTickCnt;
    clear_timer (_1000MS_);
    wait_for_timer (_1000MS_);
    d_printf_P ("wakeup!\n");   
*/

}

if (can_sleep > CAN_SLEEP_BIAS) {
    d_printf_P ("enter sleep\n");
    clear_timer (_1000MS_);
    wait_for_timer (_1000MS_);

//    my_deinit_can();
//    led_status (LED_OFF);
//    CLKPWR_Sleep();
    CLKPWR_PowerDown();
}

    }
    return 0 ;
}

Outcomes