EmbeddedRelated.com
Forums
Memfault Beyond the Launch

I2C interface for LPC2294

Started by aditiiitb February 26, 2008
Hi!
I am making a digital camera using KAC 9619 CMOS image sensor and ARM
LPC 2294. I need some help on the I2C protocol required for
controlling the sensor. Could somebody give me a sample template for
writing/reading 1 byte data into a peripheral using the LPC2294 via
the I2C protocol ?
I found one template for the PCF8570:

// Simulation of I2C Memory (Slave): like Philips PCF8570 (256 byte
I2C RAM)
MAP V:0,V:0xFF READ WRITE // Map User Memory region
DEFINE int SADR // Slave Address
signal void I2CMEMORY (void) {
unsigned long adr;
adr = V:0;
while (1) {
wwatch (I2C_OUT); // Wait for data from Microcontroller
while (I2C_OUT == 0x0100) { // START detected
wwatch (I2C_OUT); // Wait for data from Microcontroller
if (I2C_OUT > 0xFF) continue;
if ((I2C_OUT >> 1) != SADR) continue; // test if Slave is addressed
I2C_IN = 0xFF00; // ACK to Microcontroller
if (I2C_OUT & 1) { // Slave Read
while (1) {
I2C_IN = _RBYTE(adr); // Read Byte from Memory
adr++; // Increment Address
wwatch (I2C_OUT); // Wait for ACK from Microcontroller
if (I2C_OUT != 0xFF00) break;
}
}
else { // Slave Write
wwatch (I2C_OUT); // Wait for data from Microcontroller
if (I2C_OUT > 0xFF) continue;
adr = I2C_OUT | V:0; // Set Memory Address
I2C_IN = 0xFF00; // ACK to Microcontroller
while (1) {
wwatch (I2C_OUT); // Wait for data from Microcontroller
if (I2C_OUT > 0xFF) break;
_WBYTE (adr, I2C_OUT); // Store Byte in Memory
adr++; // Increment Address
I2C_IN = 0xFF00; // ACK to Microcontroller
}
}
}
}
}

I want to know if the names like I2C_OUT etc are user defined. Also,
how does the wwatch (wait and watch) function look like and which pin
does it look at.

Thanx a lot!

Aditi

An Engineer's Guide to the LPC2100 Series

Hi adit
have u looked at the lpc21xx insiders guide

http://www.hitex.co.uk/arm/lpc2000book/
this gives very nice introduction to ARM7
it includes the examples
i2c is also available in it
reply if it helps

Pradeep appala
IIT Delhi

aditiiitb wrote: Hi!
I am making a digital camera using KAC 9619 CMOS image sensor and ARM
LPC 2294. I need some help on the I2C protocol required for
controlling the sensor. Could somebody give me a sample template for
writing/reading 1 byte data into a peripheral using the LPC2294 via
the I2C protocol ?
I found one template for the PCF8570:

// Simulation of I2C Memory (Slave): like Philips PCF8570 (256 byte
I2C RAM)
MAP V:0,V:0xFF READ WRITE // Map User Memory region
DEFINE int SADR // Slave Address
signal void I2CMEMORY (void) {
unsigned long adr;
adr = V:0;
while (1) {
wwatch (I2C_OUT); // Wait for data from Microcontroller
while (I2C_OUT == 0x0100) { // START detected
wwatch (I2C_OUT); // Wait for data from Microcontroller
if (I2C_OUT > 0xFF) continue;
if ((I2C_OUT >> 1) != SADR) continue; // test if Slave is addressed
I2C_IN = 0xFF00; // ACK to Microcontroller
if (I2C_OUT & 1) { // Slave Read
while (1) {
I2C_IN = _RBYTE(adr); // Read Byte from Memory
adr++; // Increment Address
wwatch (I2C_OUT); // Wait for ACK from Microcontroller
if (I2C_OUT != 0xFF00) break;
}
}
else { // Slave Write
wwatch (I2C_OUT); // Wait for data from Microcontroller
if (I2C_OUT > 0xFF) continue;
adr = I2C_OUT | V:0; // Set Memory Address
I2C_IN = 0xFF00; // ACK to Microcontroller
while (1) {
wwatch (I2C_OUT); // Wait for data from Microcontroller
if (I2C_OUT > 0xFF) break;
_WBYTE (adr, I2C_OUT); // Store Byte in Memory
adr++; // Increment Address
I2C_IN = 0xFF00; // ACK to Microcontroller
}
}
}
}
}

I want to know if the names like I2C_OUT etc are user defined. Also,
how does the wwatch (wait and watch) function look like and which pin
does it look at.

Thanx a lot!

Aditi

---------------------------------
5, 50, 500, 5000 - Store N number of mails in your inbox. Click here.
Hi,
We are currently working using AVR Mega32 as our imported LPC2294 has not arrived as yet :(
Thanx a lot for the gr8 link though !

ChEErs
Aditi
pradeep wrote: Hi adit
have u looked at the lpc21xx insiders guide

http://www.hitex.co.uk/arm/lpc2000book/
this gives very nice introduction to ARM7
it includes the examples
i2c is also available in it
reply if it helps

Pradeep appala
IIT Delhi

aditiiitb wrote: Hi!
I am making a digital camera using KAC 9619 CMOS image sensor and ARM
LPC 2294. I need some help on the I2C protocol required for
controlling the sensor. Could somebody give me a sample template for
writing/reading 1 byte data into a peripheral using the LPC2294 via
the I2C protocol ?
I found one template for the PCF8570:

// Simulation of I2C Memory (Slave): like Philips PCF8570 (256 byte
I2C RAM)
MAP V:0,V:0xFF READ WRITE // Map User Memory region
DEFINE int SADR // Slave Address
signal void I2CMEMORY (void) {
unsigned long adr;
adr = V:0;
while (1) {
wwatch (I2C_OUT); // Wait for data from Microcontroller
while (I2C_OUT == 0x0100) { // START detected
wwatch (I2C_OUT); // Wait for data from Microcontroller
if (I2C_OUT > 0xFF) continue;
if ((I2C_OUT >> 1) != SADR) continue; // test if Slave is addressed
I2C_IN = 0xFF00; // ACK to Microcontroller
if (I2C_OUT & 1) { // Slave Read
while (1) {
I2C_IN = _RBYTE(adr); // Read Byte from Memory
adr++; // Increment Address
wwatch (I2C_OUT); // Wait for ACK from Microcontroller
if (I2C_OUT != 0xFF00) break;
}
}
else { // Slave Write
wwatch (I2C_OUT); // Wait for data from Microcontroller
if (I2C_OUT > 0xFF) continue;
adr = I2C_OUT | V:0; // Set Memory Address
I2C_IN = 0xFF00; // ACK to Microcontroller
while (1) {
wwatch (I2C_OUT); // Wait for data from Microcontroller
if (I2C_OUT > 0xFF) break;
_WBYTE (adr, I2C_OUT); // Store Byte in Memory
adr++; // Increment Address
I2C_IN = 0xFF00; // ACK to Microcontroller
}
}
}
}
}

I want to know if the names like I2C_OUT etc are user defined. Also,
how does the wwatch (wait and watch) function look like and which pin
does it look at.

Thanx a lot!

Aditi

---------------------------------
5, 50, 500, 5000 - Store N number of mails in your inbox. Click here.



---------------------------------
Save all your chat conversations. Find them online.

Memfault Beyond the Launch