Interfacing I2C-EEPROM With LPC2148: Arm How-To Guide
Interfacing I2C-EEPROM With LPC2148: Arm How-To Guide
Interfacing I2C-
EEPROM with LPC2148
Contents at a Glance
ARM7 LPC2148 Primer Board ...........................................3
I2C (Inter Integrated Circuit) ............................................3
EEPROM ..........................................................................4
Interfacing I2C - EEPROM .................................................4
Interfacing I2C EEPROM with LPC2148 ...........................6
Pin Assignment with LPC2148 ..........................................6
Circuit Diagram to Interface I2CEEPROM with LPC2148 ..7
Source Code ....................................................................7
C Program to I2C EEPROM Display using LPC2148 ..........8
Testing the I2C EEPROM with LPC2148 ........................ 16
General Information ...................................................... 18
AT24XX
ARM7 EEPROM
SDA SDA1 - (P0.14)
63
51
43
23
R34
7
U16 R35
4K7
8
4K7 U13
VDD1
VDD2
VDD3
VDDA
VREF
1
GNDVCC
6 41 5 A0 2
18 VSS1 P0.14 37 6 SDA A1 3
25 VSS2 P0.11 SCL A2 7
42 VSS3 WP
50 VSS4 AT24CXX
4
59 VSS5
VSSA 49
LPC2148 VBAT
I2C - EEPROM
XTAL2
XTAL1
61
62
12MHz
22pf 22pf
Source Code
#include <LPC214x.h>
#include <stdio.h>
#include <string.h>
#include "UART.h"
#define MAX 12
#define AA 2
#define SI 3
#define STO 4
#define STA 5
#define I2EN 6
void I2C_ISR(void)__irq;
void Wait (unsigned int);
void I2C_Init (void);
int I2C_Start (unsigned int Slave_Addr);
int I2C_Write (unsigned char *Buff, unsigned int Count);
case (0x10):
I2C1CONCLR = 1 << STA;
if (flag == 'W')
I2C1DAT = 0xA0;
else if (flag == 'R')
{
I2C1CONCLR = 1 << STA;
I2C1CONCLR = 1 << STO;
I2C1DAT = 0xA1;
I2C1CONCLR = 1 << SI;
index = 0;
}
break;
case (0x18):
I2C1CONCLR = 0x20;
I2C1CONCLR = 0x38;
}
else
{
I2C1DAT = Buff[index];
I2C1CONCLR = 0x20;
I2C1CONCLR = 0x38;
}
index++;
}
else
{
index = 0;
flag = 'R';
I2C1CONSET = 1 << STO;
if (Erase == 1)
{
UART0_PutS ("\n\r Memory
Erase uccessfull..! \n");
Erase = 0;
}
}
I2C1CONCLR = 1 << SI;
VICVectAddr = 0x00;
}
int main()
{
unsigned int i;
VPBDIV = 0x02;
PINSEL0 = 0x30C00005; //P0.11-SCLK1 & P0.14-SDA1
PINSEL2 &= 0xFFFFFFF3;
IO1DIR = 0x00 << SW3;
IO1DIR |= 0xFF << 16;
UART0_Init (9600);
VICIntSelect = 0<<19;
VICVectCntl0 = 0x020 | 19 ;
VICVectAddr0 = (unsigned long)I2C_ISR;
VICIntEnable = 1<<19;
if (Ready == 'T')
{
ii=0;
UART0_PutS ("\n\r The Read Data are: \t");
while (ii<MAX)
{
//U0THR = '\n';
Wait (1000);
U0THR = Rec[ii];
Wait (1000);
ii++;
}
UART0_PutC ('\n');
Wait (1000);
Ready = 'F';
}
while (!(IOPIN1 & SW4));
Wait (5000);Wait (5000);Wait (5000);Wait (5000);
}
if ((IOPIN1 & SW5) == 0)
{
IOCLR1 = 0xFF << 16;
IOSET1 = 1 << 18;
ii = 2;
Erase = 1;
while (ii < MAX)
{
Buff[ii] = 0xFF;
ii++;
}
flag = 'W';
I2C_Start (0x70);
for (i=0;i<30;i++) Wait(10000);
I2C1CONCLR = 1 << SI;
while (!(IOPIN1 & SW5));
Wait (5000);Wait (5000);Wait (5000);Wait (5000);
}
}
void Delay(void)
{
unsigned int i,j;
for(i=0;i<150;i++)
for(j=0;j<900;j++);
}
while(Count--)
{
I2C1DAT = *Buff++;
}
return 0;
}
General Information