i use keil software for i2c using lpc 2368 kit but i get error: #20: identifier “I2CISR” is undefined
please anybody help me.
thank you,
gajendra.
#include <lpc23xx.h> /* Defines Special function registers */
// =================================================================
// I2C Interface code based on “Insiders Guide to ARM 7” p.94-98
//
// Target uController: NXP LPC2103 @ 12.288 Mhz
//
// Dev Environment: IAR Embedded Workstation
//
// =================================================================
//
// 24C256 Pinout ( I2C memory ) 8-pin dip
// _____________
// GND -|A0 U Vcc |- Vcc (+3V?)
// GND -|A1 WP |- GND
// GND -|A2 SCL |--------------*-- P0.2
// GND -|Vss SDA |--------------*-- P0.3
// -------------
// * pull up resistor
// Address 00 when wired as shown
//
// =================================================================
// Initialize I2C Interface
void init()
{
VICVectCntl0 = 0x00000029; //select a priority slot for a given interrupt
// ********************************** PROBLEM *********************
VICVectAddr0 = (unsigned)I2CISR; //pass the address of the IRQ into the VIC slot
// *********************************************************************
VICIntEnable = 0x00000200; //enable interrupt
PINSEL0 = 0x50; //Switch GPIO to I2C pins
I20SCLH = 0x08; //Set bit rate to 57.6KHz
I20SCLL = 0x08;
}
// =================================================================
void I2CTransferByte(unsigned Addr,unsigned Data)
{
int I2CData;
int I2CAddress;
I2CAddress = Addr; //Place address and data in Globals to be used by the interrupt
I2CData = Data;
I20CONCLR = 0x000000FF; //Clear all I2C settings
I20CONSET = 0x00000040; //Enable the I2C interface
I20CONSET = 0x00000020; //Start condition
}
// =================================================================
void I2CISR (void) //I2C interrupt routine
{
int I2CAddress;
int I2CData;
switch (I20STAT) //Read result code and switch to next action
{
case ( 0x08): //Start bit
I20CONCLR = 0x20; //Clear start bit
I20DAT = I2CAddress; //Send address and
//write bit
break;
case (0x18): //Slave address+W, ACK
I20DAT = I2CData; //Write data to tx register
break;
case (0x20): //Slave address +W, Not ACK
I20DAT = I2CAddress; //Resend address and write bit
break;
case (0x28): //Data sent, Ack
I20CONSET = 0x10; //Stop condition
break;
default :
break;
}
I20CONCLR = 0x08; //Clear I2C interrupt flag
VICVectAddr = 0x00000000; //Clear interrupt in
}
// =================================================================
void I2CRead(void)
{
//The same I2CtransferByte() function can be used to start a read transaction and the
//additional case statements required in the interrupt are shown below.
unsigned char message;
int lock;
switch (I20STAT)
{
case (0x40) : //Slave Address +R, ACK
I20CONSET = 0x04; //Enable ACK for data byte
break;
case (0x48) : //Slave Address +R, Not Ack
I20CONSET = 0x20; //Resend Start condition
break;
case (0x50) : //Data Received, ACK
message = I20DAT;
I20CONSET = 0x10; //Stop condition
lock = 0; //Signal end of I2C activity
break;
case (0x58): //Data Received, Not Ack
I20CONSET = 0x20;
break;
}
}
// =================================================================
void main(void)
{
int Addr = 0x00;
int Data = 0x07;
init();
I2CTransferByte(Addr,Data);
I2CRead();
I2CISR();
}