I am working with an ATmega32-A microcontroller. Using USART communication, I am displaying data on monitor and am using switch case to select different commands. In one of the commands I have written the following code:
case(DATA):
init_io();
statusreg = AD7798_8(0x40, 0xFF);
printf("status register %02x\r\n", statusreg);
if (statusreg != 0x80)
printf("unexpected power on status %02x\r\n", statusreg);
while(1){
while ((statusreg & 0x80) != 0); // wait till ADC is ready
adc = AD7798_16(0x58, 0xFFFF); // read register
printf("ADC value is %04x\r\n", adc);
}
Command=0;
break;
But the above code is printing the ADC value infinite times. I have changed the while loop to the following
while(1){
while ((statusreg & 0x80) != 0); // wait till ADC is ready
adc = AD7798_16(0x58, 0xFFFF); // read register
printf("ADC value is %04x\r\n", adc);
}
After that it is printing only once, but does not accept any more commands. I have to re-build if I want to enter any other command. Any help appreciated.
while(1)
loops? Also, the innerwhile
loop will execute either 0 or an infinite number of iterations, depending on the value instatusreg
coming into it. This is the same problem we addressed here. \$\endgroup\$