Beispiel #1
0
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)
}
Beispiel #2
0
// Take control of the bus
void I2C_Take()
{
  I2C_CLOCK_HI();
  I2C_DATA_HI();
  SCLOUTPUT;
  SDAOUTPUT;
}
Beispiel #3
0
// Send a STOP Condition
//
void I2C_Stop(void)
{
    I2C_CLOCK_HI();
    _delay_us(I2C_DELAY);

    I2C_DATA_HI();
    _delay_us(I2C_DELAY);
}
// Send a STOP Condition
//
void i2c_stop(void)
{
    I2C_CLOCK_HI();
    _delay_us(i2cbitdelay);

    I2C_DATA_HI();
    _delay_us(i2cbitdelay);
}
Beispiel #5
0
// Send a STOP Condition
//
void I2C_Stop()
{
  I2C_CLOCK_HI();
  _delay_ms(1);

  I2C_DATA_HI();
  _delay_ms(1);
}
Beispiel #6
0
// Inits bitbanging port, must be called before using the functions below
//
void I2C_Init(void)
{
    I2C_PORT &= ~ ((1 << I2C_DAT) | (1 << I2C_CLK));

    I2C_CLOCK_HI();
    I2C_DATA_HI();

    _delay_us(I2C_DELAY);
}
void I2C_Init()
{
	I2C_PORT &= ~( ( 1 << I2C_DAT ) | ( 1 << I2C_CLK ) );

	I2C_CLOCK_HI();
	I2C_DATA_HI();

	I2C_DELAY();
}
// Inits bitbanging port, must be called before using the functions below
//
void i2c_init(void)
{
    I2C_PORT &=~ (_BV( I2C_DAT ) | _BV( I2C_CLK ));

    I2C_CLOCK_HI();
    I2C_DATA_HI();

    _delay_us(i2cbitdelay);
}
Beispiel #9
0
void I2C_Init()
{
	// I2C_PORT &= ~( ( 1 << I2C_DAT ) | ( 1 << I2C_CLK ) );
	digitalWrite(C,0,LOW);
	digitalWrite(C,1,LOW);

	I2C_CLOCK_HI();
	I2C_DATA_HI();

	I2C_DELAY();
}
Beispiel #10
0
void I2C_Stop()
{
	I2C_DATA_LO();
	I2C_CLOCK_LO();
	I2C_DELAY();

	I2C_CLOCK_HI();
	I2C_DELAY();

	I2C_DATA_HI();
	I2C_DELAY();
}
Beispiel #11
0
// Inits bitbanging port, must be called before using the functions below
//
void I2C_Init()
{

  /* Drive pins low only */
  I2C_PORT &= ~( ( 1 << I2C_DAT ) | ( 1 << I2C_CLK ) );

  /* Tri-state pins to pull up high */
  I2C_CLOCK_HI();
  I2C_DATA_HI();

  _delay_ms(1);
}
Beispiel #12
0
//! Send a STOP Condition
void I2C_Stop()
{
  I2C_DATA_LO();
  I2CDELAY(3);

  I2C_CLOCK_HI();
  I2CDELAY(3);

  I2C_DATA_HI();
  I2CDELAY(1);
  I2C_Release();
}
unsigned char i2c_readbit(void)
{
    I2C_DATA_HI();
    I2C_CLOCK_HI();
    _delay_us(i2cbitdelay);

    unsigned char c = I2C_PIN;

    I2C_CLOCK_LO();
    _delay_us(i2cbitdelay);

    return ( c >> I2C_DAT ) & 1;
}
Beispiel #14
0
//! 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);
}
Beispiel #15
0
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();
}
Beispiel #16
0
unsigned char I2C_ReadBit()
{
	I2C_DATA_HI();

	I2C_CLOCK_HI();
	I2C_DELAY();

	unsigned char c = digitalRead(C,0);

	I2C_CLOCK_LO();
	I2C_DELAY();

	return c;
}
Beispiel #17
0
unsigned char I2C_ReadBit()
{
  I2C_DATA_HI();

  I2C_CLOCK_HI();
  _delay_ms(1);

  unsigned char c = I2C_PIN;

  I2C_CLOCK_LO();
  _delay_ms(1);

  return ( c >> I2C_DAT ) & 1;
}
Beispiel #18
0
//! 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;
}
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);
}
Beispiel #20
0
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);

}
Beispiel #21
0
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();
	}
}