Reply by neptunus1000 March 30, 20052005-03-30

--- In lpc2000@lpc2..., "neptunus1000" <roykrikke@h...> wrote:
>
> Hello,
>
> I'm trying to get the I2C bus working on a LPC2129 with
CrossStudio.
> I'm already working on it for 2 day's. But no result. Is there some
one
> who can help my?
>
> Thanks

De Clock line is not working. The Data line is working. I'm confused.

The code I'm using:

#define STA 0x20
#define SIC 0x08
#define SI 0x08
#define STO 0x10
#define STAC 0x20
#define AA 0x04

class I2C{
private:

public:
I2C(void);
void delay(int);
void InitI2C(void);
void SendSlaveAdress(int addressSlave);
int ReadOnI2C(void);
void WriteOnI2C(int data);
};

I2C::I2C(void){

}
void I2C::delay(int d){
for(; d; --d){
asm volatile ("nop");
}
}

void I2C::InitI2C(void){
// Set pinouts as scl and sda
PINSEL0 |= 0x00000050;
PINSEL0 &= 0xFFFFFF5F;

I2SCLL = 400;
I2SCLH = 400;
I2CONCLR = 0xFF;
delay(10);

I2CONSET = 0x00000040; //Active Master Mode on I2C bus
} void I2C::SendSlaveAdress(int addressSlave){
if(!(addressSlave & 0x01)){ //test if it's a master adress
//while(I2C_I2STAT!=0xF8);
I2CONSET = STA;
while(I2STAT != 0x08); //Set and wait the start

I2DAT = addressSlave; // Charge slave Address
I2CONCLR = SIC | STAC; // Clear i2c interrupt bit to
send the data
while(I2STAT != 0x18 && !(I2CONSET & SI));
//wait the ACK
} else { //it's a slave adress
I2CONSET = STA;
I2CONCLR = SIC;
while(I2STAT != 0x10 && !(I2CONSET & SI)); //Set
and wait the start
I2DAT = addressSlave; // Charge slave Address
I2CONCLR = SIC | STAC; // Clear i2c interrupt bit to
send the data
while(I2STAT != 0x40 && !(I2CONSET & SI));
//wait the ACK
}
} int ReadOnI2C(void){
I2CONCLR = SIC;//ACK from the master
while(I2STAT != 0x50 && !(I2CONSET&SI)); //wait the data
// Read the data...
return I2DAT;
}

void WriteOnI2C(int data){
I2DAT = data; // Charge Data
I2CONCLR = SIC; // Clear i2c interrupt bit to send the
data
while(I2STAT != 0x28 && !(I2CONSET & SI)); //wait the ACK
}


An Engineer's Guide to the LPC2100 Series

Reply by neptunus1000 March 30, 20052005-03-30

Hello,

I'm trying to get the I2C bus working on a LPC2129 witj CrossStudio.
I'm already working on it for 2 day's. But no result. Is there some one
how can help my?

Thanks