Example #1
0
// read a byte from the I2C slave device
//
uint8_t SoftI2CMaster::i2c_read( uint8_t ack )
{
    uint8_t res = 0;

    for ( uint8_t i=0;i<8;i++) {
        res <<= 1;
        res |= i2c_readbit();  
    }

    if ( ack )
        i2c_writebit( 0 );
    else
        i2c_writebit( 1 );

    _delay_us(i2cbitdelay);

    return res;
}
Example #2
0
// write a byte to the I2C slave device
//
uint8_t SoftI2CMaster::i2c_write( uint8_t c )
{
    for ( uint8_t i=0;i<8;i++) {
        i2c_writebit( c & 128 );
        c<<=1;
    }

    return i2c_readbit();
}
Example #3
0
//
// Write a byte to the I2C slave device
// The returned bit is 0 for ACK and 1 for NACK
//
uint8_t SoftwareWire::i2c_write( uint8_t c )
{
  for ( uint8_t i=0; i<8; i++) 
  {
    i2c_writebit(c & 0x80);           // highest bit first
    c <<= 1;
  }

  return(i2c_readbit());
}
// read a byte from the I2C slave device
//
unsigned char i2c_read( unsigned char ack )
{
    unsigned char res = 0;

    for ( char i=0;i<8;i++)
    {
        res <<= 1;
        res |= i2c_readbit();  
    }

    if ( ack > 0)
        i2c_writebit( 0 );
    else
        i2c_writebit( 1 );

    _delay_us(i2cbitdelay);

    return res;
}
// write a byte to the I2C slave device
//
unsigned char i2c_write( unsigned char c )
{
    for ( char i=0;i<8;i++)
    {
        i2c_writebit( c & 128 );
   
        c<<=1;
    }

    return i2c_readbit();
}
Example #6
0
//
// read a byte from the I2C slave device
//
uint8_t SoftwareWire::i2c_read(boolean ack)
{
  uint8_t res = 0;

  for(uint8_t i=0; i<8; i++) 
  {
    res <<= 1;
    res |= i2c_readbit();
  }

  if(ack)
  {
    i2c_writebit(0);
  }
  else
  {
    i2c_writebit(1);
  }

  if(_i2cdelay != 0)
    delayMicroseconds(_i2cdelay);

  return(res);
}