Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 7 months ago.
waiting for a condition
hello all
I'm using LPC1768. I have a project that need a initialization from gps. the gps data are coming from uart. but I have a problem to make my program waiting for the initialization from the gps. here is my main program
main
void datagps (void){
// some initialization program.
// when the initialization finish it will change the gps_init flag as 0
}
int main (void){
gps.attach (&datagps);
gps_init = 1;
while (gps_init){
// do nothing
}
while (1){
// my main program
}
}
I tried to put some code at the waiting loop like this.
loop
while (gps_init){
processor.putc ('a');
}
and suddenly it works. the problem is uart at processor is needed and it cannot send anything until it is needed. thx before. sry for my english.
1 Answer
11 years, 7 months ago.
How did you define gps_init? It must be volatile, the compiler doesn't know it can be changed in an interrupt routine, and will keep checking the same value in a register instead of getting the latest from from its ram memory (if it isn't completely optimised away). So add 'volatile' in front of gps_init's definition and I assume it works.