I2C Routine
2005-08-25 by lehighuboy
Does anyone see anything wrong with the following I2C routine:?
void SendI2CAddress(unsigned char Addr_S){
I2CONCLR = 0x6C; // Clear control bits
I2CONSET = 0x40; // Active Master Mode
on I2C bus
if((Addr_S & 0x01)) // Test if reading
I2CONSET = STA | AA; // Set STA - allow
master to acknowlege slave
else
I2CONSET = STA; // Set STA don't
allow acknowledges
while(I2STAT!=0x08) ; // Wait for start to
be completed
I2DAT = Addr_S; // Load slave Address
I2CONCLR = SIC | STAC; // Clear i2c
interrupt bit to send the data
while( ! (I2CONSET & SI)) ; // Wait until status available
}
unsigned char ReadI2C(void) {
I2CONCLR = SIC; // Clear SIC;
while( ! (I2CONSET & 0x8)); // Wait until status available
// Read the data...
return I2DAT;
}
void WriteI2C(unsigned char Data) {
I2DAT = Data; // Load Data
I2CONCLR = 0x08; // SIC; Clear i2c
interrupt bit to send the data
while( ! (I2CONSET & 0x8)); // Wait until status available
}
void StopI2C(void){
I2CONCLR = SIC;
I2CONSET = STO;
while((I2CONSET & STO)) ; // Wait for Stopped I2C bus
}
The code hangs on "while((I2CONSET & STO)) ;// Wait for Stopped I2C
bus", while the chip holds both I2C lines low and doesn't release
them. I'm using the LPC2129.
Thanks!