This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADS1211 reaDING PROBLEM

Other Parts Discussed in Thread: ADS1211

Dear Sir,

 Iam not able to read data from ADC24 bit properly.kindly check my code and let me known where iam doing mistake : 

#define bit0 0x000001 //0000 0000 0000 0001
#define bit1 0x000002 //0000 0000 0000 0010
#define bit2 0x000004 //0000 0000 0000 0100
#define bit3 0x000008 //0000 0000 0000 1000
#define bit4 0x000010 //0000 0000 0001 0000
#define bit5 0x000020 //0000 0000 0010 0000
#define bit6 0x000040 //0000 0000 0100 0000
#define bit7 0x000080 //0000 0000 1000 0000

#define bit8 0x000100 //0000 0001 0000 0000
#define bit9 0x000200 //0000 0010 0000 0000
#define bit10 0x000400 //0000 0100 0000 0000
#define bit11 0x000800 //0000 1000 0000 0000
#define bit12 0x001000 //0001 0000 0000 0000
#define bit13 0x002000 //0010 0000 0000 0000
#define bit14 0x004000 //0100 0000 0000 0000
#define bit15 0x008000 //1000 0000 0000 0000

#define bit16 0x010000 //0000 0001 0000 0000
#define bit17 0x020000 //0000 0010 0000 0000
#define bit18 0x040000 //0000 0100 0000 0000
#define bit19 0x080000 //0000 1000 0000 0000
#define bit20 0x100000 //0001 0000 0000 0000
#define bit21 0x200000 //0010 0000 0000 0000
#define bit22 0x400000 //0100 0000 0000 0000
#define bit23 0x800000 //1000 0000 0000 0000


////////////////////// PIN DECLARATION ////////////////////


static bit MUX_A @ ((unsigned) & PORTA * 8 + 0); // mux selection line A
static bit MUX_B @ ((unsigned) & PORTA * 8 + 1); // mux selection line B
static bit MUX_C @ ((unsigned) & PORTA * 8 + 2); // mux selection line C
static bit STRT_CONV @ ((unsigned) & PORTA * 8 + 3); // START_CONV SELECTION SIGNAL
static bit HYDRO_TEST @ ((unsigned) & PORTA * 8 + 4); // HYDRO_TEST SELECTION
static bit ADC_MAG_SEL @ ((unsigned) & PORTA * 8 + 5); // TO SELECT XYZ-MAG AC INPUT =ADC_MAG_GAIN_SEL

static bit CH16_SEL_A0 @ ((unsigned) & PORTB * 8 + 0); // mux selection line A0 for analog switch
static bit CH16_SEL_A1 @ ((unsigned) & PORTB * 8 + 1); // mux selection line A1 for analog switch
static bit CH16_SEL_A2 @ ((unsigned) & PORTB * 8 + 2); // mux selection line A2 for analog switch
static bit CH16_SEL_A3 @ ((unsigned) & PORTB * 8 + 3); // mux selection line A3 for analog switch
static bit ADC16_BUSY @ ((unsigned) & PORTB * 8 + 4); // ADC16_BUSY SIGNAL FROM U14
static bit ZADC_DRDY @ ((unsigned) & PORTB * 8 + 5); //DATA READY PIN FROM Z MAG-ADC TO MICROCONTROLLER
static bit XADC_DRDY @ ((unsigned) & PORTB * 8 + 6); //DATA READY PIN FROM X MAG-ADC TO MICROCONTROLLER
static bit YADC_DRDY @ ((unsigned) & PORTB * 8 + 7); //DATA READY PIN FROM Y MAG-ADC TO MICROCONTROLLER

static bit DAC_LATCH @ ((unsigned) & PORTC * 8 + 0); // latch signal for DAC U13 DAC4814
static bit DAC_EN @ ((unsigned) & PORTC * 8 + 1); //
static bit ADC16_RST @ ((unsigned) & PORTC * 8 + 2); // RESET SIGNAL FOR U14 MAX
static bit SPI_SCL @ ((unsigned) & PORTC * 8 + 3); //SPI clock
static bit SPI_SDI @ ((unsigned) & PORTC * 8 + 4); //SPI Input
static bit SPI_SDO @ ((unsigned) & PORTC * 8 + 5); // SPI output

///////////UART INITIALIZATION FOR SERIAL COMMUNICATION-ASYNCHRONOUS ////////////////
void UART_int()
{
PEIE=1; // // Peripheral Interrupt Enable bit
SPBRG=31; // 9600 baurate =31,312.5KBPS=307200 stdandard baudrate low selected BRGH='0',SPBRG=20x10000000/(64x312500)-1 ='0'
TXSTA=0b00100010; //CSRC=0;TX9=0;TXEN=1;Async=0;-=0;BRGH=0;TRMT(transmit shift register TSR is empty)=1;TX9D=0;
BRGH=0; // low baudrate selected
TXEN=1; // enable transmit
TXIF = 0;// intrupt flag for transmit
RCSTA=0b10010000; //sereial port en, continous receive en,SPEN serial port =1;RX9=0;SREN=0;CREN=1 continous control rec;ADDEN=0;FERR=0;OERR=0;RX9D=0;
RCIE=1; // rec intruppt
RCIF = 0; // intrupt flag for receive
GIE=1; // general purpose intrupt
OPTION = 0B00001000;
T0IE = 1; //enable TMR0 overflow interrupts
TMR0=0; // TIMER START ACFLAG FROM 0;
TMR0IE=1; //Enable TIMER0 Interrupt
// SSPSTAT=0b11000001;
// SSPCON=0b01100000;
}
///////////UART TRANSMISSION FOR SERIAL COMMUNICATION-ASYNCHRONOUS ////////////////
void UART_WRITE(char TX_BYTE)
{

TXIF=0;
TXREG=TX_BYTE;
while(!TXIF){;};

}

void interrupt ISR (void) // Interrupt function definition
{
unsigned char i;
if(RCIF==1) //receiver interrupt
{
RX_BYTE = RCREG; // copy receve register to receive buffer
RCIF = 0; // clear rec flag intrupt
}
while(!T0IF);
{
T0IF=0;
}
}

/*==============================================================================================*/
/* send hex byte on serial port */
/*==============================================================================================*/

void send_hex(unsigned char c)
{
unsigned char ch,cl;
ch=c;
ch&=0xf0;ch>>=4;
if(ch<10){ch+='0';}
else{ch+=('A'-10);}
cl=c;
cl&=0x0f;
if(cl<10){cl+='0';}
else cl+=('A'-10);
UART_WRITE(ch);
UART_WRITE(cl);
}
void send_int(unsigned int i)
{
unsigned char j;
unsigned char k;
j=i;

i=i>>8;
send_hex(i);
DelayMs(10);
send_hex(j);
DelayMs(10);
}

void send_long(unsigned long i)
{
unsigned int j;
unsigned int k;
j=i;

i=i>>16;
send_int(i);
DelayMs(10);
send_int(j);
DelayMs(10);
}
void comp2_hex(long f)
{

f=~f;
comp= f + 1;
// send_long(comp);

}


void config_ADC(void)
{
long comand=0xE20427A0; // comand=0xC2000013; not working wen 1 byte is 00 ;
ADC_reset();
ADC_self_cal();
set_command(comand);
}
//-------------------------check data is ready ///////////////////////////

void ADS_wait(void)
{
while(ZADC_DRDY==0); //waiting DRDY=1
// while(ZADC_DRDY==1); //waiting DRDY=1
}
//------------------------------write to INSR register-----------------//
void write_adc_instr(char data) //send 1 instr. byte INSR AND CMR REG CONTROL THE OPERATION OF CONVERSION OK
{
ADS_wait();
write_adc_byte(data);
}
//----------------------/// CMR register////////// INSR AND CMR REG CONTROL THE OPERATION OF CONVERSION OK
void set_command(long value)
{
write_adc_instr(0x64); //write to command CMR 3BYTE MSB addres 0100 for 1 byte
write_adc_4byte(value);
ADS_wait();
}
//--------------------- //self calibration OK
void ADC_self_cal(void)
{
write_adc_instr(0x05); // insr command reg byte 1,ADD CMR at byte 0 REFER DATASHEETS PAGE 19 ADDRESS
write_adc_byte(0x20); // insr 2 byte selectec mb0=1,DOR address 0000 for 2 byte
ADS_wait();
}

//------------------- write 1 byte data --------------------------//
void write_adc_byte(char add) //send 1 instr. byte checked OK
{
unsigned char i=0,temp;
// DelayMs(4);
for(i =8;i >=1;i--)
{
SPI_SCL=1;
temp=add;
temp =temp >> (i-1);
temp= temp & 0x01;
// send_hex(temp);
if(temp == 0x01)
{
SPI_SDO =1;
}
else
{
SPI_SDO =0;
}

SPI_SCL=0;
// DelayMs(4);

}
}
//--------------------- write 4 byte data CMR register -------------//
void write_adc_4byte(long add) //sen 4 byte serial check OK
{
unsigned char i=0;
long temp;
// DelayMs(4);

for(i =32;i >=1;i--)
{
SPI_SCL=1;
temp=add;
temp =temp >> (i-1);
temp= temp & 0x01;
// send_hex(temp);
if(temp == 0x01)
{
SPI_SDO =1;
}
else
{
SPI_SDO =0;
}

SPI_SCL=0;
// DelayMs(4);

}
}
//----------------------------write 3 byte data for DOR,FCR,OCR register ----------//
void write_adc_3byte(long add) //sen 3 byte serial checked OK
{
unsigned char i;
long temp;
// DelayMs(4);
for(i =24;i >=1;i--)
{
SPI_SCL=1;
temp=add;
temp =temp >> (i-1);
temp= temp & 0x01;
// send_hex(temp);
if(temp == 0x01)
{
SPI_SDO =1;
}
else
{
SPI_SDO =0;
}

SPI_SCL=0;
// DelayMs(4);

}
}

//---------------------
void set_ADC_offset(long value) ///// OCR register//////////// OCR AND FCR REG CONVERTING THE INTERNAL CORRECTION BRFORE PLACING ON DOR OK
{
write_adc_instr(0x48); //write ocr register ADDRESS BYTE2 MSB
write_adc_3byte(value); // DATA
}
//----------------------------
void set_ADC_full(long value) ////FCR register //////////////////////// OCR AND FCR REG CONVERTING THE INTERNAL CORRECTION BRFORE PLACING ON DOR OK
{
write_adc_instr(0x4C); // WRITE 2 BYTE MSB FCR REG IN INSR
write_adc_3byte(value); // DATA
}
//--------------------
void ADC_reset(void) //reset ADS1211
{

SPI_SCL=0;
SPI_SCL=1;
// DelayMs(37); //300*Txy
SPI_SCL=0;
// DelayMs(5);
SPI_SCL=1;
// DelayMs(87); //300*Txy
SPI_SCL=0;
// DelayMs(5);
SPI_SCL=1;
// DelayMs(137); //300*Txy
SPI_SCL=0;
// DelayMs(5);
SPI_SCL=1;
// DelayMs(187); //300*Txy
SPI_SCL=0;

}
//------------------------------Read DOR --------------------------------//
long read_adc_3byte() //read 3 Bytes
{
unsigned char i = 0;
for(i=1;i<25;i++)
{
SPI_SCL=1;
switch(i)
{
case 1:

if(SPI_SDI == 1)
{
ADS_DATA = ADS_DATA | bit0;
SPI_SCL=0;
}
if(SPI_SDI == 0)
{
ADS_DATA = ADS_DATA & 0xFFFFFFFE;
SPI_SCL=0;
}

//break;


case 2:

if(SPI_SDI == 1)
{
ADS_DATA = ADS_DATA | bit1;
SPI_SCL=0;
}
if(SPI_SDI == 0)
{
ADS_DATA = ADS_DATA & 0xFFFFFFFD;
SPI_SCL=0;
}

// break;


case 3:

if(SPI_SDI == 1)
{
ADS_DATA = ADS_DATA | bit2;
SPI_SCL=0;
}
if(SPI_SDI == 0)
{
ADS_DATA = ADS_DATA & 0xFFFFFFFB;
SPI_SCL=0;
}

// break;


case 4:

if(SPI_SDI == 1)
{
ADS_DATA= ADS_DATA | bit3;
SPI_SCL=0;
}
if(SPI_SDI == 0)
{
ADS_DATA = ADS_DATA & 0xFFFFFFF7;
SPI_SCL=0;
}
// break;

case 5:

if(SPI_SDI == 1)
{
ADS_DATA = ADS_DATA | bit4;
SPI_SCL=0;
}
if(SPI_SDI == 0)
{
ADS_DATA = ADS_DATA & 0xFFFFFFEF;
SPI_SCL=0;
}
// break;


case 6:

if(SPI_SDI == 1)
{
ADS_DATA = ADS_DATA | bit5;
SPI_SCL=0;
}
if(SPI_SDI == 0)
{
ADS_DATA = ADS_DATA & 0xFFFFFFDF;
SPI_SCL=0;
}
// break;


case 7:

if(SPI_SDI == 1)
{
ADS_DATA = ADS_DATA | bit6;
SPI_SCL=0;
}
if(SPI_SDI == 0)
{
ADS_DATA = ADS_DATA & 0xFFFFFFBF;
SPI_SCL=0;
}
// break;


case 8:

if(SPI_SDI == 1)
{
ADS_DATA = ADS_DATA | bit7;
SPI_SCL=0;
}
if(SPI_SDI == 0)
{
ADS_DATA = ADS_DATA & 0xFFFFFF7F;
SPI_SCL=0;
}
// break;


case 9:

if(SPI_SDI == 1)
{
ADS_DATA = ADS_DATA | bit8;
SPI_SCL=0;
}
if(SPI_SDI == 0)
{
ADS_DATA = ADS_DATA & 0xFFFFFEFF;
SPI_SCL=0;
}
// break;


case 10:

if(SPI_SDI == 1)
{
ADS_DATA = ADS_DATA | bit9;
SPI_SCL=0;
}
if(SPI_SDI == 0)
{
ADS_DATA= ADS_DATA & 0xFFFFFDFF;
SPI_SCL=0;
}

// break;


case 11:

if(SPI_SDI == 1)
{
ADS_DATA = ADS_DATA | bit10;
SPI_SCL=0;
}
if(SPI_SDI == 0)
{
ADS_DATA = ADS_DATA & 0xFFFFFBFF;
SPI_SCL=0;
}
// break;


case 12:

if(SPI_SDI == 1)
{
ADS_DATA = ADS_DATA| bit11;
SPI_SCL=0;
}
if(SPI_SDI == 0)
{
ADS_DATA = ADS_DATA & 0xFFFFF7FF;
SPI_SCL=0;
}
// break;


case 13:

if(SPI_SDI == 1)
{
ADS_DATA = ADS_DATA | bit12;
SPI_SCL=0;
}
if(SPI_SDI == 0)
{
ADS_DATA= ADS_DATA & 0xFFFFEFFF;
SPI_SCL=0;
}
// break;


case 14:

if(SPI_SDI == 1)
{
ADS_DATA= ADS_DATA | bit13;
SPI_SCL=0;
}
if(SPI_SDI == 0)
{
ADS_DATA = ADS_DATA & 0xFFFFDFFF;
SPI_SCL=0;
}
// break;

case 15:

if(SPI_SDI == 1)
{
ADS_DATA = ADS_DATA | bit14;
SPI_SCL=0;
}
if(SPI_SDI == 0)
{
ADS_DATA = ADS_DATA & 0xFFFFBFFF;
SPI_SCL=0;
}
// break;

case 16:

if(SPI_SDI == 1)
{
ADS_DATA = ADS_DATA | bit15;
SPI_SCL=0;
}
if(SPI_SDI == 0)
{
ADS_DATA= ADS_DATA & 0xFFFF7FFF;
SPI_SCL=0;
}
// break;

case 17:

if(SPI_SDI == 1)
{
ADS_DATA = ADS_DATA | bit16;
SPI_SCL=0;
}
if(SPI_SDI == 0)
{
ADS_DATA= ADS_DATA & 0xFFFEFFFF;
SPI_SCL=0;
}
// break;

case 18:

if(SPI_SDI == 1)
{
ADS_DATA = ADS_DATA | bit17;
SPI_SCL=0;
}
if(SPI_SDI == 0)
{
ADS_DATA= ADS_DATA & 0xFFFDFFFF;
SPI_SCL=0;
}
// break;

case 19:

if(SPI_SDI == 1)
{
ADS_DATA = ADS_DATA | bit18;
SPI_SCL=0;
}
if(SPI_SDI == 0)
{
ADS_DATA= ADS_DATA & 0xFFFBFFFF;
SPI_SCL=0;
}
// break;

case 20:

if(SPI_SDI == 1)
{
ADS_DATA = ADS_DATA | bit19;
SPI_SCL=0;
}
if(SPI_SDI == 0)
{
ADS_DATA= ADS_DATA & 0xFFF7FFFF;
SPI_SCL=0;
}
// break;
case 21:
if(SPI_SDI == 1)
{
ADS_DATA = ADS_DATA | bit20;
SPI_SCL=0;
}
if(SPI_SDI == 0)
{
ADS_DATA= ADS_DATA & 0xFFEFFFFF;
SPI_SCL=0;
}
// break;

case 22:
if(SPI_SDI == 1)
{
ADS_DATA = ADS_DATA | bit21;
SPI_SCL=0;
}
if(SPI_SDI == 0)
{
ADS_DATA= ADS_DATA & 0xFFDFFFFF;
SPI_SCL=0;
}
// break;
case 23:
if(SPI_SDI == 1)
{
ADS_DATA = ADS_DATA | bit22;
SPI_SCL=0;
}
if(SPI_SDI == 0)
{
ADS_DATA= ADS_DATA & 0xFFBFFFFF;
SPI_SCL=0;
}
// break;

case 24:
if(SPI_SDI == 1)
{
ADS_DATA = ADS_DATA | bit23;
SPI_SCL=0;
}
if(SPI_SDI == 0)
{
ADS_DATA= ADS_DATA & 0xFF7FFFFF;
SPI_SCL=0;
}
// break;


default:
break;
}

}
SPI_SCL=0;
// DelayMs(1);
return ADS_DATA;
}

//-----------------------
long read_DOR() //read DOR register OK
{
long DOR_data;
write_adc_instr(0xC0); //read DOR register 2 bytes MSB beginig in addres 0000 FROM INSR
DOR_data=read_adc_3byte(); //read the 3 bytes
return DOR_data;
}
//----------------------------
long read_ADC_off() //Read OFF register OK
{
long off_data;
write_adc_instr(0xC8); //order for read 2 bytes MSB in addres 1000
off_data=read_adc_3byte(); //read the 3 bytes
return off_data;
}
//------------------------------
long read_ADC_full() //Read FULL register OK
{
long full_data;
write_adc_instr(0xCC); //order for read 2 MSB bytes beginig in addres 1100
full_data=read_adc_3byte(); //read the 3 byte
return full_data;
}
///////////////////////////////////MAIN FUNCTION ///////////////////////////
void main(void)
{

TRISA=0b00000000; // mux selection A,B,C output=0,STARt CONV,HYDRO_TEST;AC_MAG_GAIN=;
TRISB=0b11110000; // CHANNEL SELECTION A0-A3=0;ADC16_BUSY,X,Y,ZADC_DRDY=1
TRISC=0b11010001; // spi SDO,clk output=0,SDI input=1;TX=1;RX=1
ADCON1=0x86;

// MUX_SEL(4); // ZADC_CS SELECTED= 0; cs=0

config_ADC();

while(1)
{

DOR_BUFFER = read_DOR(); // READ DOR REGISTER IN ADC CONVERSION RESULT STORE


}
}

  • Hi Arti,
    What processor are you using ?
    Who written this code ?
    TO provided or own ?
    What problem you are facing exactly ?
    Can you please elaborate a bit on your problem.
  • Hi Titus,
    What processor are you using ? - PIC16F876A
    Who written this code ? - Myself
    TO provided or own ? - Own
    What problem you are facing exactly ? - same count iam getting for all analog input voltages
    Can you please elaborate a bit on your problem. - Iam I have a doudt iam able to read data properly or not iam getting for different analog input voltage same counts,some time count is changing also but same this its repeating for all input votage.and serial output wave form iam getting always same square waveform.
  • Hi Arti,

    Moved your query to appropriate forum.

    ----
  • Hi Arti,

    You have provided a lot of code, and I'm not super familiar with PIC processors and that would require a huge amount of time for me to follow the code sequence as it has very few comments.  As to your problem, can you send me your schematic?

    As for the communication, you state that you get the same value for conversion data.  First of all, can you read and write to the command registers?  Can you tell me what you are using for the command register settings?

    What would be most helpful is for me to see either oscilloscope or logic analyzer shots of the communication.  Usually there is either a setup issue or a timing issue. 

    One curiosity question.  This is an incredibly complicated part so why did you choose to use it?  We have many far less complicated parts that are easier to configure and use.

    Best regards,

    Bob B

  • Hi sir,

    IAm using ADS1211P ADC IC.I have given CMR proper but iam not getting pulses on serial out pin ,It always coming 0.where i gave CS always 0,DRDY pin iamgetting only problem with Serial out pin always 0.

  • Hi Arti,

    You will not have any data coming out the SDOUT pin unless you have programmed the SDL bit (Bit 1) high in the CMR byte 3 register.  Can you send me your schematic?  Can you send me some logic analyzer/oscilloscope shots of the communication?

    Best regards,

    Bob B

  • Hi Bob,

    Iam able to read CMR and now my ADC is working.I have connected seperatly ADC circuit outside from my design.I have a doudt ,Can you please tell me known why iam facing this problem:

    1. if i give /CS from MUX iam not able to read CMR same thime when ill connect /CS with ground,Iam able to read CMR and ADC is working.

    2. When switch off power supply iam not able to read DOR reason (/DRDY and SDO pin no pulses),again I have to flash code,after flashing code its start working fine.whereas when i will read CMR after power off iam able to read CMR without again code flash.

    Kindly guide me why iam facing this problem?

  • Hi Arti,

    You really haven't given me much information and I'm not there to observe your setup (see my previous post for requested information).  It is like calling a doctor and saying 'I don't feel well, what is wrong?'

    I suspect that you have a grounding/power issue with the mux.  You must make sure that the ADS1211 ground and the mux ground are the same.  You should also measure and make sure that the CS pin is truly going low.

    As to why the ADC stops running, you need to see what else is happening on the device pins.    Did you check the state of all the digital pins between the ADS1211 and the powered down micro?  If you are using the micro to provide the ADC clock, then the ADC will stop functioning.  These are my best guesses.

    Best regards,

    Bob B