9 years, 4 months ago.

Confusing LPC11U24 Program

The following code iterates through main twice for some reason using the LPC11U24, if I port the code to the 1768 it only goes through main once (as I would expect). Am I missing something silly? Thanks for any help. Kyle.

// Short test program to check ADXL335

#include "mbed.h"

AnalogIn Sense(p20);
Serial PC(USBTX,USBRX);
DigitalOut LED(LED1);

float Get_Sample(void);

int main()
{
    volatile int N = 0;
    wait(1);
    LED = 1;
    
    while(N <= 50) {
        float Sample = Get_Sample();
        N++;
    }
    LED = 0;
    PC.printf("N = %d\n\r",N);
}



float Get_Sample()
{
    float M_Sample = Sense.read()*3.3;
    PC.printf("Value = %0.2f\n\r", M_Sample);
    wait_ms(100);
    return M_Sample;
}

1 Answer

9 years, 4 months ago.

It is best to end your main function simply with a while(1); statement. This will hold the program there, removing any ambiguity.

No idea why it would then stop after the second time though.