Hello,
I’m trying to get the I2C bus working on the LPC-E2129 Development board. I program with CrossStudio. This is working great. I can debug with the JTAG interface very nice.
I think I initialize the I2C good. You can find the code I used at the end of this messaged.
If I look in the scheme of the development board, I see that there is a pull-up resistor on the SDA line. This is resistor R37, connected to the 3.3 Volt en the SDA line. There is no pull-up resistor on the SCL line. Why? In my measurement with a scope a can see that there is some activity on the SLC line and no activity on the SDA line. But this I can see only if I connected a 8K pull-up resistor to the SLC line. I don’t understand this. Can some one please help my.
Thanks
//main.cpp
#include <targets/LPC210x.h>
#include "I2C.h"
#define CAM_ADDRESS 0xA0
int main(void){
I2C i2c;
i2c.InitI2C();
while(1){
i2c.SendSlaveAdress(CAM_ADDRESS);
}
return 0;
}
//I2C.h
#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
}