Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[ARM] I2C interfacing using interrupts in LPC2138

Status
Not open for further replies.

Ravindrakant Jha

Junior Member level 2
Junior Member level 2
Joined
Nov 2, 2014
Messages
24
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Location
India
Visit site
Activity points
274

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <LPC213X.H>
unsigned int I2Caddress;  //global variable for address
unsigned int I2Cdata;   //global variable for data
unsigned char *message;
void i2c_isr(void)__attribute__((interrupt("IRQ"))); //interrupt service routine
void i2c_transfer_byte(unsigned add,unsigned data); //function for transferring bytes
void i2c_receive_byte(void);     //function for receiving
void i2c_init()   //I2C initialization
{
  
  VICVectCntl1=0X00000029;// vectored control pin for I2C
  VICVectAddr1=(unsigned)i2c_isr;//passing IRQ address to the VIC slot
  VICIntEnable = 0x00000200; //enable interrupt
  PINSEL0|=0X50;//selecting  pin for I2C
  I2C0SCLL= 0X08;  //for a frequency of 57.6 KHz
  I2C0SCLH= 0X08;
}
void i2c_transfer_byte(unsigned add,unsigned data)
{   
    I2Caddress=add;
    I2Cdata=data;
    I2C0CONCLR=0X000000FF;//clear all I2c settings
    I2C0CONSET=0X00000040;//enable I2C 
    I2C0CONSET=0X00000020;//start condition
}
void i2c_isr(void)
{
    switch(I2C0STAT)
    {
      case(0X08): I2C0CONCLR=0X20; //clear start bit
                  I2C0DAT=I2Caddress;
                  break;
      case(0X18): I2C0DAT=I2Cdata; //send data 
                  break;
      case(0X20):I2C0DAT=I2Caddress;//resend slave address+W
                  break;
      case(0X28):I2C0CONSET=0X00000010;//stop condition
                  break;
    }
    I2C0CONCLR=0X08;//i2c interrupt clear bit
    VICVectAddr=0X00000000; //clear all interrupts
}
void i2c_receive_byte(void)
{
   switch(I2C0STAT)
   {
     case(0X40):I2C0CONSET=0x04; //SLAVE +READ+ack
                break;
     case(0X48):I2C0CONSET=0X20;//resend start condition
                break;
     case(0X50):*message=I2C0DAT; //receive data into message buffer
                I2C0CONSET=0X10;
                break;
     case(0X58):I2C0CONSET=0X20;//data received ,resend start condition
                break;
  }
  
}
int main()
{
  int addr=0X00;
  i2c_init();
  i2c_transfer_byte(addr,'R');
  i2c_receive_byte();
  i2c_isr();
}



by executing above code the interrupt enable bit is not getting set though i declared in the i2c_init function as well on the keil i2c module data is shown only received with the value shown 02!
 
Last edited by a moderator:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top