7 years, 3 months ago.

LPC 11U35 Deep Sleep and wake up

Hello, I use deep sleep mode and external interrupt for wake up MCU. At beginning of code or Int main() sleep mode is called. GPS module When position of GPS module is fixed then GPS modul launchs external interrupt of MCU (P0_17) and MCU is waked. This is ok and it works good. The problem is when sleep mode is called by function GPS_Status. The external interrupt does not work and MCU never is waked. I do not know why.


#include "mbed.h"
#include "USBSerial.h"
#include "MODSERIAL.h"
#include "at25sf041.h"
#include "string"

//#include "rtos.h"
uint8_t check[] = {0xB5, 0x62, 0x06, 0x08, 0x00, 0x00, 0x0E, 0x30};
uint8_t Power_save[] =  {0xB5, 0x62, 0x06, 0x11, 0x02, 0x00, 0x08, 0x01, 0x22, 0x92};
uint8_t Eco_mode[] = {0xB5, 0x62, 0x06, 0x11, 0x02, 0x00, 0x08, 0x04, 0x25, 0x95};
//uint8_t Timepulse_10sec[] = {0xb5, 0x62, 0x06, 0x08, 0x06, 0x00, 0x10, 0x27, 0x01, 0x00, 0x01, 0x00, 0x4D, 0xDD};
uint8_t OFF[] = {0xB5, 0x62, 0x06, 0x04, 0x04, 0x00, 0x00, 0x00,0x08, 0x00, 0x16, 0x74};
uint8_t Update_10sec[] = {0xB5, 0x62, 0x06, 0x3B, 0x2C, 0x00, 0x01, 0x06, 0x00, 0x00, 0x00, 0x90, 0x02, 0x00, 0x10, 0x27, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x2C, 0x01, 0x00, 0x00, 0x4F, 0xC1, 0x03, 0x00, 0x86, 0x02, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x64, 0x40, 0x01, 0x00, 0xE1, 0x51};
//uint8_t Update10sec[] = {0xB5, 0x62, 0x06, 0x3B, 0x2C, 0x00, 0x01, 0x06, 0x00, 0x00, 0x00, 0x90, 0x03, 0x00, 0x10, 0x27, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x2C, 0x01, 0x00, 0x00, 0x4F, 0xC1, 0x03, 0x00, 0x87, 0x02, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x64, 0x40, 0x01, 0x00, 0xE4, 0x8B};
uint8_t Timepulse_10sec[] = {0xB5, 0x62, 0x06, 0x31, 0x20, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x96, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x86, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF3, 0x00, 0x00, 0x00, 0x20, 0x28};
uint8_t GPSoff[] = {0xB5, 0x62, 0x06, 0x04, 0x04, 0x00, 0x00, 0x00,0x08, 0x00, 0x16, 0x74};
uint8_t GPSon[] = {0xB5, 0x62, 0x06, 0x04, 0x04, 0x00, 0x00, 0x00,0x09, 0x00, 0x17, 0x76};
uint8_t GPSoff_all[] = {0xB5, 0x62, 0x02, 0x41, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x4D, 0x3B};

DigitalOut out1(P0_2);
DigitalOut out2(P0_4);
DigitalOut out3(P0_5);
DigitalOut out4(P0_7);
DigitalOut out5(P0_12);
DigitalOut out6(P0_16);
DigitalOut out7(P0_20);
DigitalOut out8(P0_21);
DigitalOut out9(P0_22);
DigitalOut out10(P0_23);
DigitalOut out11(P1_19);

Ticker LED_Timepulse;
Ticker Poll_ticker;
Timeout Sleep_flipper;



DigitalOut Led_Red(P0_13);
DigitalOut Led_Green(P0_14);
DigitalOut USB_connect(P0_6);
AnalogIn ain(P0_11);

USBSerial usb(0x1f00, 0x2012, 0x0001, false);
DigitalIn Vbus(P0_3);
AT25SF041 memory(P0_9, P0_8, P0_10, P0_15);

MODSERIAL uart(P0_19, P0_18);
InterruptIn GPS_fix(P0_17);
volatile bool newline_detected = false;
int save_mode = 0;
int sleep_state = 0;

int i = 0;
int t = 0;
char tmp[30];

void cfg_poll(void);
void cfg_disable_output(void);
void cfg_power_save(void);
void cfg_update_10(void);
void cfg_timepulse_10(void);
void cfg_eco_mode(void);
void cfg_gpsoff(void);
void cfg_gpson(void);
void cfg_gpsoff_all(void);
void sleep_mcu(void);

void Start_cfg()
{
    for (int a = 0; a < 3; a++) {
        Led_Red = 1;
        Led_Green = 1;
        wait (0.2);
        Led_Red = 0;
        Led_Green = 0;
        wait (0.2);
    }
    cfg_disable_output();
    //  wait(1);
    //  cfg_timepulse_10();
    //Poll_ticker.attach(&cfg_poll, 5);



    return;

}

void Rx_interrupt(MODSERIAL_IRQ_INFO *q)
{
    Led_Red = !Led_Red;
    MODSERIAL *serial = q->serial;
    if ( serial->rxGetLastChar() == '\n') {
        newline_detected = true;

    }

}

void GPS_Status()
{
    Led_Green = 1;
    wait(0.1);
    Led_Green = 0;
    if (save_mode == 0) {
        cfg_timepulse_10();
        save_mode = 1;
    }
    LED_Timepulse.detach();
    cfg_poll();
    wait (1);
    sleep_mcu();

}

void GPS_Interrupt()
{

    LED_Timepulse.attach(&GPS_Status, 1);


}

void usb_rx()
{

    if (usb.available()) {
        tmp[1] = usb.getc();
        usb.putc(tmp[1]);

        switch (tmp[1]) {
            case 'q':
                cfg_power_save();
                break;
            case 'w':
                cfg_update_10();
                break;
            case 'e':
                cfg_timepulse_10();
                break;
            case 'a':
                cfg_eco_mode();
                break;
            case 'z':
                cfg_disable_output();
                break;
            case 'p':
                cfg_poll();
                break;
            case 'n':
                cfg_gpsoff();
                break;
            case 'm':
                cfg_gpson();
                break;
            case 'x':
                cfg_gpsoff_all();
                break;
            case 's':
                sleep_mcu();
                break;

        }
    }


}

void flushSerialBuffer(void)
{
    // LedStatus = !LedStatus;
    char char1;
    while (uart.readable()) {
        char1 = uart.getc();
    }
    return;
}

void sleep_mcu(void)
{

    LPC_PMU->PCON = 0x1;
    SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
    LPC_SYSCON->PDAWAKECFG &= 0xFFFFF800;
    __WFI();

}

void cfg_power_save(void)
{
    for (int a = 0; a< sizeof (Power_save); a++) {

        uart.putc(Power_save[a]);

    }

    uart.putc('\n');
}

void cfg_eco_mode(void)
{
    for (int a = 0; a< sizeof (Eco_mode); a++) {

        uart.putc(Eco_mode[a]);

    }

    uart.putc('\n');
}

void cfg_gpsoff_all(void)
{
    for (int a = 0; a< sizeof (GPSoff_all); a++) {

        uart.putc(GPSoff_all[a]);

    }

    uart.putc('\n');
}

void cfg_update_10(void)
{
    for (int a = 0; a< sizeof (Update_10sec); a++) {

        uart.putc(Update_10sec[a]);

    }

    uart.putc('\n');
}

void cfg_timepulse_10(void)
{
    for (int a = 0; a< sizeof (Timepulse_10sec); a++) {

        uart.putc(Timepulse_10sec[a]);

    }

    uart.putc('\n');
}

void cfg_gpsoff(void)
{
    for (int a = 0; a< sizeof (GPSoff); a++) {

        uart.putc(GPSoff[a]);

    }

    uart.putc('\n');
}

void cfg_gpson(void)
{
    for (int a = 0; a< sizeof (GPSon); a++) {

        uart.putc(GPSon[a]);

    }

    uart.putc('\n');
}

void cfg_disable_output(void)
{

    uart.printf("$PUBX,40,GLL,0,0,0,0*5C\r\n");
    wait(0.3);
    uart.printf("$PUBX,40,GSA,0,0,0,0*4E\r\n");
    wait(0.3);
    uart.printf("$PUBX,40,RMC,0,0,0,0*47\r\n");
    wait(0.3);
    uart.printf("$PUBX,40,GSV,0,0,0,0*59\r\n");
    wait(0.3);
    uart.printf("$PUBX,40,VTG,0,0,0,0*5E\r\n");
    wait(0.3);
    uart.printf("$PUBX,40,GGA,0,0,0,0*5A\r\n");

}

void cfg_poll(void)
{

    uart.printf("$PUBX,00*33\r\n");
    //Led_Red = !Led_Red;

}




int main()
{
    uart.baud(9600);
    //cfg_disable_output();
    Start_cfg();

    out1 = 0;
    out2 = 0;
    out3 = 0;
    out4 = 0;
    out5 = 0;
    out6 = 0;
    out7 = 0;
    out8 = 0;
    out9 = 0;
    out10 = 0;
    out11 = 0;

    USB_connect = 0;
    GPS_fix.rise(&GPS_Interrupt);
    usb.attach(&usb_rx);
    uart.attach(&Rx_interrupt, MODSERIAL::RxIrq);
    if (!Vbus) {
        sleep_mcu();
    }



    while (1) {


        if (newline_detected) {

            newline_detected = false;
            char c;
            while((c = uart.getc()) != '\n') {
                usb.putc(c);
            }
            usb.putc('\n');
            Led_Red = !Led_Red;
            //sleep_mcu();
            // sleep_state = 0;

        } else {
            flushSerialBuffer();

        }
        //  sleep_state = 0;


    }

}
Be the first to answer this question.