Skip to main content
Added reference link, improved formatting and grammar, removed thanks, added question
Source Link
embedded.kyle
  • 8.6k
  • 2
  • 28
  • 45

I am trying to read external ADC AD7798AD7798 values using ATmega32-A controller. In the datasheet, Status register Bit7Bit 7 (SR7) indicates the conversion is finished or not.:

Status register Bit7 is like "Ready Bit. Cleared when data is written to the data register. Set after the data register is read or after a period of time before the data register is updated with a new conversion result to indicate to the user not to read the conversion data. It is also set when the part is placed in power-down mode. The end of a conversion is indicated by the DOUT/RDY pin. This pin can be used as an alternative to the status register for monitoring the ADC for conversion data."

Ready Bit. Cleared when data is written to the data register. Set after the data register is read or after a period of time before the data register is updated with a new conversion result to indicate to the user not to read the conversion data. It is also set when the part is placed in power-down mode. The end of a conversion is indicated by the DOUT/RDY pin. This pin can be used as an alternative to the status register for monitoring the ADC for conversion data.

Now iI want to write code to check if the Status register MSB  (Bit7) is "0"0 or not. So when it is "0"then0, only Ithen can I issue a read command.

I have written code like this.:

unsigned char CheckStatus(void)
{
            char adcStatus; 
            spi(0x40);
            adcStatus = spi(0xFF);
            while((adcStatus & 0x80)!=0x80);                         
            return adcStatus;
}

butBut it is not working. My

My code explanation:

  1. issuingIssuing the read command to read ADC status register.
  2. Reading ADC status register value and stored in adcStatus variable.
  3. Checking the MSB bit is not equal to 1. (I am not sure if this while loop is correct or not.)

2)Reading ADC status register value and stored in "adcStatus" variable.

3)checking the MSB bit is not equal to "1". (I am not sure this while loop is correct or not.

I want to check statusif the Status register MSB is not equal to "1".1 so that I can issue the read command "0x58"in Reading(0x58) to read in the ADC values. The last bit Bit7If the status register MSB is "1"thenequal to 1 then I can't read ADC values.

Please help me.

Thanks.What am I doing wrong?

I am trying to read external ADC AD7798 values using ATmega32-A controller. In the datasheet, Status register Bit7 indicates the conversion is finished or not.

Status register Bit7 is like "Ready Bit. Cleared when data is written to the data register. Set after the data register is read or after a period of time before the data register is updated with a new conversion result to indicate to the user not to read the conversion data. It is also set when the part is placed in power-down mode. The end of a conversion is indicated by the DOUT/RDY pin. This pin can be used as an alternative to the status register for monitoring the ADC for conversion data."

Now i want to write code to check Status register MSB(Bit7) is "0" or not. So when it is "0"then only I can issue read command.

I have written code like this.

unsigned char CheckStatus(void)
{
            char adcStatus; 
            spi(0x40);
            adcStatus = spi(0xFF);
            while((adcStatus & 0x80)!=0x80);                         
            return adcStatus;
}

but it is not working. My code explanation

  1. issuing the read command to read ADC status register.

2)Reading ADC status register value and stored in "adcStatus" variable.

3)checking the MSB bit is not equal to "1". (I am not sure this while loop is correct or not.

I want to check status register MSB is not equal to "1". so that I can issue read command "0x58"in Reading ADC values. The last bit Bit7 is "1"then I can't read ADC values.

Please help me.

Thanks.

I am trying to read external ADC AD7798 values using ATmega32-A controller. In the datasheet, Status register Bit 7 (SR7) indicates the conversion is finished or not:

Ready Bit. Cleared when data is written to the data register. Set after the data register is read or after a period of time before the data register is updated with a new conversion result to indicate to the user not to read the conversion data. It is also set when the part is placed in power-down mode. The end of a conversion is indicated by the DOUT/RDY pin. This pin can be used as an alternative to the status register for monitoring the ADC for conversion data.

Now I want to write code to check if the Status register MSB  (Bit7) is 0 or not. So when it is 0, only then can I issue a read command.

I have written code like this:

unsigned char CheckStatus(void)
{
            char adcStatus; 
            spi(0x40);
            adcStatus = spi(0xFF);
            while((adcStatus & 0x80)!=0x80);                         
            return adcStatus;
}

But it is not working.

My code explanation:

  1. Issuing the read command to read ADC status register.
  2. Reading ADC status register value and stored in adcStatus variable.
  3. Checking the MSB bit is not equal to 1. (I am not sure if this while loop is correct or not.)

I want to check if the Status register MSB is not equal to 1 so that I can issue the read command (0x58) to read in the ADC values. If the status register MSB is equal to 1 then I can't read ADC values.

What am I doing wrong?

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

Problem with while loop

I am trying to read external ADC AD7798 values using ATmega32-A controller. In the datasheet, Status register Bit7 indicates the conversion is finished or not.

Status register Bit7 is like "Ready Bit. Cleared when data is written to the data register. Set after the data register is read or after a period of time before the data register is updated with a new conversion result to indicate to the user not to read the conversion data. It is also set when the part is placed in power-down mode. The end of a conversion is indicated by the DOUT/RDY pin. This pin can be used as an alternative to the status register for monitoring the ADC for conversion data."

Now i want to write code to check Status register MSB(Bit7) is "0" or not. So when it is "0"then only I can issue read command.

I have written code like this.

unsigned char CheckStatus(void)
{
            char adcStatus; 
            spi(0x40);
            adcStatus = spi(0xFF);
            while((adcStatus & 0x80)!=0x80);                         
            return adcStatus;
}

but it is not working. My code explanation

  1. issuing the read command to read ADC status register.

2)Reading ADC status register value and stored in "adcStatus" variable.

3)checking the MSB bit is not equal to "1". (I am not sure this while loop is correct or not.

I want to check status register MSB is not equal to "1". so that I can issue read command "0x58"in Reading ADC values. The last bit Bit7 is "1"then I can't read ADC values.

Please help me.

Thanks.