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:
- issuingIssuing the read command to read ADC status register.
- Reading ADC status register value and stored in
adcStatus
variable. - Checking the MSB bit is not equal to
1
. (I am not sure if thiswhile
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?