Skip to main content
Tweeted twitter.com/#!/StackElectronix/status/258583537178005505

I am working with ATmega32-A micro controlleran ATmega32-A microcontroller.Using Using USART communication, I am displaying data on monitor.I and am using switch case to select different commands. In one of the commandcommands I have written the following code like:

 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;

butBut the above code is printing the ADC value infinite times. I have changed the while loop like thisto 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 it isdoes not accepting anymoreaccept any more commands. It got stucked there. I have to re-build if I want to enter any other command. anyAny help appreciated.

I am working with ATmega32-A micro controller.Using USART communication I am displaying data on monitor.I am using switch case to select different commands. In one of the command I have written code like

 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 ADC value infinite times. I have changed the while loop like this

   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 it is not accepting anymore commands. It got stucked there. I have to re-build if I want to enter any other command. any help appreciated.

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.

Source Link
verendra
  • 1.3k
  • 2
  • 14
  • 25

Loop is executing infinite times

I am working with ATmega32-A micro controller.Using USART communication I am displaying data on monitor.I am using switch case to select different commands. In one of the command I have written code like

 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 ADC value infinite times. I have changed the while loop like this

   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 it is not accepting anymore commands. It got stucked there. I have to re-build if I want to enter any other command. any help appreciated.