6 years, 9 months ago.

Why interrupt does not work

Hello,

I am using LPC11U35 and GPS module Ublox. When i disable GPS output then Rx interrupt is blocked or it does not work. I do not know why. When i send letter "e" to GPS module then GPS module should answer but i get no answer. Can you help me ?

#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};
//int a;
//Set GPIO out
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;



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;
//volatile bool character_o = false;
int i = 0;
char tmp[30];

void cfg_poll(void);
void cfg_disable_output(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();

    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;
    LED_Timepulse.detach();

}

void GPS_Interrupt()
{
    LED_Timepulse.attach(&GPS_Status, 0.5);
    
}

/*void usb_rx()
{

    if (usb.getc() == 'l') {
//character_o = true;
        cfg_poll();
    }

        else if (usb.getc() == 'k') {
        cfg_disable_output();
        }


}*/

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

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");


}




int main()
{
    uart.baud(9600);

    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);

    while (1) {

        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':
                    LPC_PMU->PCON = 0x2;
                    SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
                    LPC_SYSCON->PDAWAKECFG &= 0xFFFFF800;
                    __WFI();
                    break;

            }


        }

        if (newline_detected) {

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

        //  else {
        //   flushSerialBuffer();
        //usb.sprintf("\r\n");
        // }



    }

}

Hello Peter,
What does " When I disable GPS output " mean? If you disable serial output from the GPS then there are probably no serial messages coming to your mbed board to trigger serial interrupt ..?

posted by Zoltan Hudak 29 Jul 2017

Hello Zoltan, GPS module sends NMEA mesages once a second. It is default setting. The function cfg_disable_output disables all NMEA mesages. When I call function cfg_poll this function sends request to GPS module and GSP module should send position mesage to mbed board but this does not work.

posted by Peter Augustin 30 Jul 2017

Hello Peter,
When does the signal on GPS_fix line rise? Maybe the GPS interrupt occurs at the same time or slightly sooner than the serial interrupt and only the GPS_Interrupt ISR is called. Try to comment out the line

    //GPS_fix.rise(&GPS_Interrupt);
posted by Zoltan Hudak 31 Jul 2017
Be the first to answer this question.