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:
And Write function:
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.
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: