SparkFun Forums 

Where electronics enthusiasts find answers.

Everything ARM and LPC
By gajendra_808
#118523
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();

}
By krkan
#118525
I am not using Keil compiler or IDE with ARM, but have been using it on 8051.

So:
1.) You are trying to use something before it is declared in the code (I suppose that you are programming in C and not C++)
2.) Is VICVectAddr0 pointer to a function?
3.) Why are you calling I2CISR(); from the main?
4.) Where are attributes or pragmas that are defining I2CISR as an interrupt function?
5.) Or is it called from some "real" interrupt function that is not listed in this code? That would be a bad programming practice.
6.) Where is some kind of endless loop in order to prevent the program exiting the main function?
And to where will it go after executing "main"? It is returning void. Is there any kind of startup (or asm code) that is actually behind the scene and calling the "main"?



-------
http://dimkoelectronics.wordpress.com
By gajendra_808
#118527
yes, lpc 2368 is use the start up file and lpc 23xx.h header file

but i get error on I2CSIR , SO please help me.
thank you,
gajendra.