D deexith hasan New Member Sep 4, 2014 #1 I can able to understand transmitting data through I2C..but in receiving data its tough for me.. in this website i can see 2 SCL and SDA https://www.robot-electronics.co.uk/acat.../I2C_Tutorial.html C: unsigned char i2c_rx(char ack) { char x, d=0; SDA = 1; for(x=0; x<8; x++) { d <<= 1; do { SCL = 1; } while(SCL_IN==0); // wait for any SCL clock stretching i2c_dly(); if(SDA_IN) d |= 1; SCL = 0; } if(ack) SDA = 0; else SDA = 1; SCL = 1; i2c_dly(); // send (N)ACK bit SCL = 0; SDA = 1; return d; } in this program where i cant find any digitalread..... Last edited by a moderator: Sep 4, 2014
I can able to understand transmitting data through I2C..but in receiving data its tough for me.. in this website i can see 2 SCL and SDA https://www.robot-electronics.co.uk/acat.../I2C_Tutorial.html C: unsigned char i2c_rx(char ack) { char x, d=0; SDA = 1; for(x=0; x<8; x++) { d <<= 1; do { SCL = 1; } while(SCL_IN==0); // wait for any SCL clock stretching i2c_dly(); if(SDA_IN) d |= 1; SCL = 0; } if(ack) SDA = 0; else SDA = 1; SCL = 1; i2c_dly(); // send (N)ACK bit SCL = 0; SDA = 1; return d; } in this program where i cant find any digitalread.....
Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member Sep 4, 2014 #2 I placed your code in "Code" tags to make it easier to read... If(SDA_IN) d |= 1; .... This line reads the I2C bus.. d <<= 1; ... This line shifts the receive buffer.. This happens for 8 iterations....
I placed your code in "Code" tags to make it easier to read... If(SDA_IN) d |= 1; .... This line reads the I2C bus.. d <<= 1; ... This line shifts the receive buffer.. This happens for 8 iterations....
D deexith hasan New Member Sep 5, 2014 #3 thanq its now clear that there is read line in I2C rx....but in I2C only 2 pins are needed (SDA,SCL) then what about SDA_IN and SCL_IN pin??
thanq its now clear that there is read line in I2C rx....but in I2C only 2 pins are needed (SDA,SCL) then what about SDA_IN and SCL_IN pin??
Ian Rogers User Extraordinaire Forum Supporter Most Helpful Member Sep 5, 2014 #4 Its the same pin.... They are just named so you can read it clearer.. It you look at my tutorials ( I think its Tutorial 6 ) I have made software I2C routines... I have clearly remarked on the operation.. The link is in my signature..
Its the same pin.... They are just named so you can read it clearer.. It you look at my tutorials ( I think its Tutorial 6 ) I have made software I2C routines... I have clearly remarked on the operation.. The link is in my signature..