We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
hello sir/mam, i want to use i2c interface for my project in which i m using the LPC2468 microcontroller. i m using keil software.i got one code for i2c that is as follows but in this i have some quaries can u please help me. code: #include "LPC213x.h" void initialize(void); __irq void I2C_ISR(void); /* Master Transmitter states */ void ISR_8(void); void ISR_18(void); void ISR_28(void); /*************************** MAIN ************************/ int main() { /* Initialize system */ initialize(); /* Send start bit */ I2C0CONSET=0x60; /* Do forever */ while(1) { IOCLR0=0x40; IOSET0=0x40; } } /*************** System Initialization ***************/ void initialize() { /* Remap interrupt vectors to SRAM */ MEMMAP=0x2; /* Initialize GPIO ports to be used as indicators */ IODIR0=0xF0; IOSET0=0xF0; /* Initialize Pin Connect Block */ PINSEL0=0x50; /* Initialize I2C */ I2C0CONCLR=0x6c; /* clearing all flags */ I2C0CONSET=0x40; /* enabling I2C */ I2C0SCLH=0xC; /* 100 KHz */ I2C0SCLL=0xD; /* Initialize VIC for I2C use */ VICIntSelect=0x0; /* selecting IRQ */ VICIntEnable= 0x200; /* enabling I2C */ VICVectCntl0= 0x29; /* highest priority and enabled */ VICVectAddr0=(unsigned long) I2C_ISR; /* ISR address written to the respective address register*/
} /********************** I2C ISR **************************/ __irq void I2C_ISR() { int temp=0; temp=I2C0STAT; switch(temp) { case 8: ISR_8(); break; case 24: ISR_18(); break; case 40: ISR_28(); break; default : break; } VICVectAddr=0xFF; } /* I2C states*/ /* Start condition transmitted */ void ISR_8() { /* Port Indicator */ IOCLR0=0x10; /* Slave address + write */ I2C0DAT=0x74; /* Clear SI and Start flag */ I2C0CONCLR=0x28; /* Port Indicator */ IOSET0=0x10; }
/* Acknowledgement received from slave for slave address */ void ISR_18() { /* Port Indicator */ IOCLR0=0x20; /* Data to be transmitted */ I2C0DAT=0x55; /* clear SI */ I2C0CONCLR=0x8; /* Port Indicator */ IOSET0=0x20; } /* Acknowledgement received from slave for byte transmitted from master. Stop condition is transmitted in this state signaling the end of transmission */ void ISR_28() { /* Port Indicator */ IOCLR0=0x80; /* Transmit stop condition */ I2C0CONSET=0x10; /* clear SI */ I2C0CONCLR=0x8; /* Port Indicator */ IOSET0=0x80; } /********************************************************/ in this code i m not getting what is I2C_ISR..in this code initialization is perfect but after that it is going to the infinite loop..in the startup code it is going in the infinite loop....and i m also not getting what is the meaning of LDR PC, [PC, #-0x0120]..after that while loop it is coming on this lable which is in the startup file and then not comming out....can u please help me..thank u.
Your code isn't really readable - follow the instructions about how to post source code. See the text just above the text box where you write your message.
Your code doesn't seem to do anything meaningful. In main(), you issue a start bit, and then the state functions performed hard-coded operations.
You are expected to add own code to actually do something - controlling if you are going to read or write, specify what address to access, and what data to transfer.
The interrupt is part of a state machine. It is expected to trig a couple of times. Not much will come out of it since you haven't teached the state functions to actually perform any job.
Your main() code is expected to busy-loop, since you don't give it anything meaningful to do.
Have you visited NXP and retrieved their documentation about the I2C bus and the distinctive states the I2C controller will take when doing a read (single byte or sequential) or a write (single byte or sequential)?
NXP is the inventor of the I2C bus, and they have quite good documentation available.
hello sir, i have visited nxp..and this code is also provided by philips..i m also not getting why he had use that while loop??