Stragling to read ADC value from AD7794

Status
Not open for further replies.

mohanchandra

New Member
Hi
I am interfaced ADU812 with AD7794.Controller and ADC are communicating
properly.I am reading status of ADC register.

In this register, RDY (7 bit of STATUS REGISTER) bit always high.
while(1)
{
SPI_SendAdc(CR_STATUSREG); //Read Status of Register
send_bit_serial(status=SPI_ReadADC());
send_byte('C');
NextLine();
if(!(status&0x80))
break;
}
or
SPI_SendAdc(CR_DATA_RD);//
while(RDY_ADC==1);//wait till RDY_ADC=0
Problem: RDY_ADC pin(MISO) it is continously high. How we know completion of conversion



Anybody give me a solution for this problem and also if i get ADC value then
how i convert this adc to normal temparature.(V ref: 1.7v internal reference voltage).



I am waiting for your positve reply

Regards
Mohanchandra


I am trying to read the internal temparature value.Code is pasted below


sbit ADC_CHIP_SELECT = P0^0 ;
sbit RDY_ADC = P3^3;
#define CS_LOW ADC_CHIP_SELECT = 0;
#define CS_HIGH ADC_CHIP_SELECT= 1;
#define CR_MODE_WR 0x08 //00001000
#define CR_CONFIG_WR 0x10 //00010000
#define CR_DATA_RD 0x5C //01011000//single conversion read
#define MODEREG_HIGH 0x20 //mode register Sinle conversion.64KHz internal clock
#define MODEREG_LOW 0x10
#define CONFIGREG_HIGH 0x10 //Configuration register,unipolar with 1.17 ref voltage,channel
#define CONFIGREG_LOW 0x86//temp sensor
#define CR_STATUSREG 0x40 //01000000
void main()
{
unsigned int i;
unsigned char ucCount=5,status;
serial_init();
Spi_Initialization();
while((ucCount--)>1)
{
P0 = 0x00; P1 = 0x00; P2 = 0x00; P3 = 0x00;
for(i=0;i<20000;i++);
P0 = 0xFF; P1 = 0xFF; P2 = 0xFF; P3 = 0xFF;
for(i=0;i<20000;i++);
send_byte('A');
}
//=========================Writing operation====================
CS_LOW; //enable
for(i=0;i<1000;i++);
SPI_SendAdc(CR_MODE_WR); //Mode register
SPI_SendAdc(MODEREG_HIGH);
SPI_SendAdc(MODEREG_LOW);

SPI_SendAdc(CR_CONFIG_WR); //Configuration register
SPI_SendAdc(CONFIGREG_HIGH);
SPI_SendAdc(CONFIGREG_LOW);

CS_HIGH; //disable
for(i=0;i<10000;i++);
//=========================Reading operation====================
//Read mode register
while(1)
{
CS_LOW; //enable
for(i=0;i<1000;i++);
/*while(1)
{
SPI_SendAdc(CR_STATUSREG); //Read Status of Register
send_bit_serial(status=SPI_ReadADC());
send_byte('C');
NextLine();
if(!(status&0x80))
break;
}*/
//Dispaly data in NextLine
//==========================================================
SPI_SendAdc(CR_DATA_RD);
while(RDY_ADC==1);//wait till RDY_ADC=0

send_bit_serial(SPI_ReadADC()); //24 bit adc data
send_bit_serial(SPI_ReadADC());
send_bit_serial(SPI_ReadADC());
CS_HIGH; //Disable
send_byte('B');
NextLine(); //Dispaly data in NextLine
for(i=0;i<10000;i++);
}

}
//======================================================================

void serial_init()
{
TMOD=0X20; //Timer 1....Mode 2...Auto Reload
TH1=0XFD; //Baud Rate 9600 FD
SCON=0X50; //Mode 1..8 bit data,..1 stop bit,..1 start bit
TR1=1;
RI=0;
TI=0;
}

void send_byte(unsigned char add)
{
SBUF=add;
while(TI==0);
TI=0;
}
void Spi_Initialization()
{
SPICON=0x3E; //ISPI WCOL SPE SPIM CPOL CPHA SPR1 SPR0

}
//Next line dispaly
void NextLine()
{
send_byte(0x0D);
send_byte(0x0A);
}
//Send data to ADC device throug SPI Communication Protocal
void SPI_SendAdc(unsigned char SPI_DATA)
{
ISPI=0; //cler the flagh
SPIDAT=SPI_DATA; //load the 8 bit data to SPI data register
while(ISPI==0); //wait till flag will set
ISPI=0;

}
//Read data from ADC
unsigned char SPI_ReadADC()
{
unsigned char ucData=0;
ISPI=0; //cler the flagh
SPIDAT=0; //load the 8 bit data to SPI data register
while(ISPI==0); //wait till flag will set
ucData=SPIDAT;
return(ucData);
}
//send bitwise digital data to serial
void send_bit_serial(unsigned char ucData)
{
unsigned char ucCount=0;
for(ucCount=0;ucCount<8;ucCount++)
{
if((ucData<<ucCount)&0x80)
send_byte(0x31);
else
send_byte(0x30);
}

}
 
Last edited:
Hey i know nothing of that controller but this seem ODD... why have 2 different SPI type functions. I think this one below should be fine but the one below it .. how does it send data through SPI?
Code:
void send_byte(unsigned char add)
{
SBUF=add;
while(TI==0);
TI=0;
}
void Spi_Initialization()
{
SPICON=0x3E; //ISPI WCOL SPE SPIM CPOL CPHA SPR1 SPR0

Code:
//Send data to ADC device throug SPI Communication Protocal
void SPI_SendAdc(unsigned char SPI_DATA)
{
ISPI=0; //cler the flagh
SPIDAT=SPI_DATA; //load the 8 bit data to SPI data register
while(ISPI==0); //wait till flag will set
ISPI=0;

}

Maybe you should send data through the first one only?
also you are aware that :

send_bit_serial(status=SPI_ReadADC());

is sending 8 bytes rights? (not bits)
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…