ADS1100 16-bit ADC with MikroC

Status
Not open for further replies.

Vizier87

Active Member
Hi guys, I ordered ADS1100 samples and they turn out to be very important for my work now. I wrote a code to read it via I2C, but it's not working yet. Here's the timing diagram of the ADS1100:
View attachment 67830
View attachment 67831

Basically I'm using a PIC as a Master and the ADS1100 is slave only.

Hope you guys can comment on my Rx and Tx functions first before I post the whole code:

Read function:
C:
void i2c_rx_highbyte (){
   data_dir=1;        // receiving bit
   
   for(k=1;k<9;k++){
     buffer=0x00;
     sclk=1;
     delay();
     highbyte=highbyte+((buffer+sda)>>k);   // MSB first
     sclk=0;
     delay();
   }

     sclk=1;
     delay();                   // wait for ACK
     if (sdata==0){             // if ADS1100 pulls SDA low upon the next clock, it acknowledges the written byte
      delay();
      sclk=0;                   // pull the clock down
     }
}

And Write function:

C:
void i2c_tx (unsigned int j){    // transmitting data to ADS1100
   data_dir=0;          // j is the data to be sent


   for(k=0;k<8;k++)
   {
     sclk=0;
     delay();
     if((j<<k)&& 0x80==0x80){
     sdata=1;    // output high on data out (nth bit high = data)
     }
     else sdata=0;
     delay();
     sclk=1;
     delay();
   }
   delay();
     
     data_dir=1;
     sclk=1;
     delay();                   // wait for ACK
     if (sdata==0){             // if ADS1100 pulls SDA low upon the next clock, it acknowledges the written byte
      delay();
      sclk=0;                   // pull the clock down
     }
}

Thanks for the time spent on this. I am a beginner in C, but hopefully I organized them properly for all of you to peruse.

Vizier87.
 
Last edited:
Hi guys,
Bit banging is too tedious, so I grudgingly shifted to using the library. It proved to be 100% simpler. 15 LEDs light up at full swing. Now I'm trying to combine the data for display via an LCD, but for certain reasons this happens. Say the code is this:

C:
unsigned short int x_, highbyte, lowbyte;
    
     Soft_I2C_Start();
     Soft_I2C_Write(0x91);
     highbyte=Soft_I2C_Read(1);
     lowbyte=Soft_I2C_Read(0);
     Soft_I2C_Stop();


x_ = highbyte;    // display highbyte only
*transform into digits via LCD*
The result is a full swing of 127 displayed nicely. (it loses 1 bit for single ended inputs). The same occurs for the lowbyte, full swing of 255.

However, when I combine both registers to make a 15-bit number like this:

C:
x_ = highbyte*256+lowbyte;

The LCD displays rubbish. I suppose the problem is with my declaration of the variables? How do go around this?

Thanks.
Vizier87.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…