Keil Logo

I2C interrupts

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Details Message
Read-Only
Author
arun raj
Posted
11-Apr-2011 12:06 GMT
Toolset
ARM
New! I2C interrupts

This is the example code i used for the simulation in keil.

after runs the simulation, the status reg changes to 0x08, but not entering to interrupt service routine.

#include <LPC21xx.H>

unsigned char I2CAddress;
unsigned char I2CData;


void I2CISR (void)              // I2C interrupt routine
{
switch (I2STAT)                 // Read result code and switch to next action
{
case ( 0x08):                   // Start bit
I2CONCLR = 0x28;        // Clear start bit
I2DAT = I2CAddress;     // Send address and
                                                // write bit
break;
case (0x18):                    // Slave address+W, ACK
I2DAT = I2CData;                 // Write data to tx register
 break;
case (0x20):                    // Slave address +W, Not ACK
I2DAT = I2CAddress;     // Resend address and write bit
 break;
case (0x28):                    // Data sent, Ack
I2CONSET = 0x10;                // Stop condition
 break;
 default :
 break;
 }

I2CONCLR = 0x08;   // Clear I2C interrupt flag
VICVectAddr = 0x00000000; // Clear interrupt in
}

void init()
{

VICVectCntl1 = 0x00000029;       // select a priority slot for a given interrupt
VICVectAddr1 = (unsigned)I2CISR;
VICIntEnable = 0x00000200;
PINSEL0 = 0x50;
I2SCLH  = 0x08;
I2SCLL  = 0x08;

}

void I2CTransferByte(unsigned Addr,unsigned Data) {

I2CAddress = Addr; // Place address and data in Globals to be used by
                                        // the interrupt
I2CData = Data;
I2CONCLR = 0xFF; // Clear all I2C settings
I2CONSET = 0x40; // Enable the I2C interface
I2CONSET = 0x20; // Start condition
}



void main()
{
init();
I2CTransferByte(0x81,0x90);

while(1);

}
Read-Only
Author
Per Westermark
Posted
11-Apr-2011 12:23 GMT
Toolset
ARM
New! RE: I2C interrupts

If you use a NXP LPC21xx, then where did you get that "sample code" from?

Didn't the sample code specify __irq for the interrupt handler?

Read-Only
Author
arun raj
Posted
11-Apr-2011 13:52 GMT
Toolset
ARM
New! RE: I2C interrupts

The below code is NXP example.

still HAVE THAT PROBLEM

#include"LPC210x.h"

void Initialize(void);

/* I2C ISR */
__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 */
I2CONSET=0x60;

/* Do forever */
while(1)
{
IOCLR=0x40;
IOSET=0x40;
}

}
/*************** System Initialization ***************/


void Initialize()
{
IODIR=0xF0;
IOSET=0xF0;

/*initializing I2C */
PINSEL0 = 0x50;

I2CONCLR = 0x6c;
I2CONSET = 0x40;


I2SCLH  = 0x08;
I2SCLL  = 0x07;

/* 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*/
}

__irq void I2C_ISR()
{
int temp=0;
temp=I2STAT;
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 */
IOCLR=0x10;
/* Slave address + write */
I2DAT=0x74;
/* Clear SI and Start flag */
I2CONCLR=0x28;
/* Port Indicator */
IOSET=0x10;
}

/* Acknowledgement received from slave for slave address */
void ISR_18()
{
/* Port Indicator */
IOCLR=0x20;
/* Data to be transmitted */
I2DAT=0x55;
/* clear SI */
I2CONCLR=0x8;
/* Port Indicator */
IOSET=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 */
IOCLR=0x80;
/* Transmit stop condition */
I2CONSET=0x10;
/* clear SI */
I2CONCLR=0x8;
/* Port Indicator */
IOSET=0x80;
}
/********************************************************/

Next Thread | Thread List | Previous Thread Start a Thread | Settings

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.