unsigned char I2C_ReadBit_Wait() { SDAINPUT; I2C_CLOCK_HI(); unsigned int i = 0; unsigned char c = READSDA; while(c>0 && i<=35) { I2CDELAY(1); c = READSDA; i++; } if(c) I2C_DATA_HI(); else I2C_DATA_LO(); SDAOUTPUT; I2CDELAY(1); I2C_CLOCK_LO(); I2CDELAY(1); return c?0:1; // return true on ACK (0) }
void i2c_writebit( unsigned char c ) { if ( c > 0 ) { I2C_DATA_HI(); } else { I2C_DATA_LO(); } I2C_CLOCK_HI(); _delay_us(i2cbitdelay); I2C_CLOCK_LO(); _delay_us(i2cbitdelay); if ( c > 0 ) { I2C_DATA_LO(); } _delay_us(i2cbitdelay); }
//! Send a START Condition void I2C_Start() { I2C_Take(); // XXX Should probably check to see if someone else is using the bus before we do this I2CDELAY(3); I2C_DATA_LO(); I2CDELAY(3); I2C_CLOCK_LO(); I2CDELAY(1); }
//! Send a STOP Condition void I2C_Stop() { I2C_DATA_LO(); I2CDELAY(3); I2C_CLOCK_HI(); I2CDELAY(3); I2C_DATA_HI(); I2CDELAY(1); I2C_Release(); }
void I2C_WriteBit( unsigned char c ) { if ( c > 0 ){ I2C_DATA_HI(); } else { I2C_DATA_LO(); } I2C_CLOCK_HI(); _delay_ms(1); I2C_CLOCK_LO(); _delay_ms(1); if ( c > 0 ) I2C_DATA_LO(); _delay_ms(1); }
// Send a START Condition // void I2C_Start() { // set both to high at the same time I2C_DDR &= ~( ( 1 << I2C_DAT ) | ( 1 << I2C_CLK ) ); _delay_ms(1); I2C_DATA_LO(); _delay_ms(1); I2C_CLOCK_LO(); _delay_ms(1); }
void I2C_Stop() { I2C_DATA_LO(); I2C_CLOCK_LO(); I2C_DELAY(); I2C_CLOCK_HI(); I2C_DELAY(); I2C_DATA_HI(); I2C_DELAY(); }
// Send a START Condition // void i2c_start(void) { // set both to high at the same time I2C_DDR &=~ (_BV( I2C_DAT ) | _BV( I2C_CLK )); _delay_us(i2cbitdelay); I2C_DATA_LO(); _delay_us(i2cbitdelay); I2C_CLOCK_LO(); _delay_us(i2cbitdelay); }
// Send a START Condition // void I2C_Start(void) { // set both to high at the same time I2C_DDR &= ~ ((1 << I2C_DAT) | (1 << I2C_CLK)); _delay_us(I2C_DELAY); I2C_DATA_LO(); _delay_us(I2C_DELAY); I2C_CLOCK_LO(); _delay_us(I2C_DELAY); }
//! Write an I2C bit. void I2C_WriteBit( unsigned char c ) { if(c>0) I2C_DATA_HI(); else I2C_DATA_LO(); I2C_CLOCK_HI(); I2CDELAY(1); I2C_CLOCK_LO(); I2CDELAY(1); }
void I2C_WriteBit( unsigned char c ) { if ( c > 0 ) { I2C_DATA_HI(); } else { I2C_DATA_LO(); } I2C_CLOCK_HI(); I2C_DELAY(); I2C_CLOCK_LO(); I2C_DELAY(); if ( c > 0 ) { I2C_DATA_LO(); } }
void I2C_Start() { // set both to high at the same time // I2C_DDR &= ~( ( 1 << I2C_DAT ) | ( 1 << I2C_CLK ) ); I2C_CLOCK_HI(); I2C_DATA_HI(); I2C_DELAY(); I2C_DATA_LO(); I2C_DELAY(); I2C_CLOCK_LO(); I2C_DELAY(); }
//! Read an I2C bit. unsigned char I2C_ReadBit() { SDAINPUT; I2C_CLOCK_HI(); unsigned char c = READSDA; if(c) I2C_DATA_HI(); else I2C_DATA_LO(); SDAOUTPUT; I2CDELAY(1); I2C_CLOCK_LO(); I2CDELAY(1); return c; }