Owner's manual
KTD-S0003-C Page 25 CPLD Interface
pITX-SP Software Guide
SDA_High ();
I2C_Delay ();
bit_in = I2C_Bit_In ();
if (bit_in)
i2c_error = I2C_ERR_NAK;
return i2c_error;
}
//*********************************************************
//* Reads one byte in from the slave. Ack must be 1 if this
//* is the last byte to be read during this transfer, 0
//* otherwise (as per I2C bus specification, the receiving
//* master must acknowledge all but the last byte during a
//* transfer)
//*********************************************************
int I2C_Byte_In (void)
{
int bit_count = 8, byte_in = 0;
SDA_High ();
I2C_Delay ();
while (bit_count)
{
byte_in <<= 1;
if (I2C_Bit_In ())
byte_in |= TRUE;
bit_count--;
}
SDA_High ();
I2C_Delay ();
I2C_Bit_In (); // Set acknowledge
return byte_in;
}
//*********************************************************
//* Writes a byte to I2C device (main routine)
//*********************************************************
int WriteI2CDevice (int device_addr, int byte_write)
{
I2C_Reset ();
I2C_Stop ();
I2C_Start ();
if (I2C_Byte_Out (device_addr))
return FALSE;
if (I2C_Byte_Out (byte_write))
return FALSE;
I2C_Stop ();
return TRUE;
}