Discussion in "ARM Development" started by    nari    Mar 31, 2009.
Tue Mar 31 2009, 04:18 pm
#1
Hay
I am facing problem with LPC2114 inbuilt I2C, i interfaced LPC2114 with PCF8574AP Port Expander.
I have tested following code but the salve device (PCF8574AP) not responding.
My application is I have to read the Digital inputs from the PCF8574AP device
PCF8574AP device address Pins A0, A1, A2 connected to the ground
Please provide the information regarding how to read the inputs from the I2C Port Expander.



///////////////////////////////I2C-Testing-Code///////////////////////
#include<LPC21XX.h>

#define LED1 0x00000010 //P0.4
#define LED2 0x00000040 //P0.6
#define LED3 0x00000080 //P0.7
#define LED4 0x00000400 //P0.10

unsigned char I2CAddress = 0x71; // set I2C slave address for read from the chip

void init_pll()
{
PLLCFG=0x00;//multiplier and divider values are 00
PLLCON=0x00; //PLL is bypassed and the oscillator clock is used directly by the LPC2114,PLL is turned off
PLLFEED=0xAA; //Feed values
PLLFEED=0x55;
VPBDIV=0x01; //VPB bus clock is the same as the processor clock Pclk=14.7MHZ, Cclk=14.7MHZ
}

void I2C0_Isr(void) __irq
{
unsigned char st;
st = I2STAT;
switch(st)
{
case 0x08: //when start bit is enable status of the regeater is 0x08

I2CONCLR=0X20;//Clear start bit
IO0SET=LED1;
delay();
I2DAT=I2CAddress; //send the address with read bit 01110001=0x71
break;


case 0x40: //slave address +R,ACK

I2CONSET = 0x04; // enable ACK for data byte
IO0SET=LED2;
delay();
break;

case 0x48: //slave address+R, Not ACK

I2CONSET = 0x20; // Resend the start condition
IO0SET=LED3;
break;

case 0x10: //Repet Start condition Data Recived ,Not ACK
I2CONCLR = 0x20; // Clear the start condition
I2DAT=I2CAddress; //send the address with read bit 01110001
IO0SET=LED4;
delay();
break;

default:
break;
}
I2CONCLR=0x08; // clear SI
VICVectAddr = 0; // reset VIC
}

void main()
{
unsigned int i;
init_pll();
PINSEL0 |= 0x50; //select the SDA,SCL pins
IODIR0=0x00FFFFF0;
I2CONCLR=0x6c; /* clearing all flags */
I2CONSET=0x40; /* enabling I2C */
I2SCLH=0x08; /* 56.7 KHz */
I2SCLL=0x08;
/* Initialize VIC for I2C use */
VICVectAddr0 = (unsigned int) &I2C0_Isr;
VICVectCntl0 = 0x29; // Channel1 on Source#9 ... enabled
VICIntEnable |= 0x200;
/* ISR address written to the respective address register*/
/* Send start bit */
I2CONSET=0x60;
delay(); //

while(1)
{

i++;
delay();
i--;
}

}

Regards
Chandu
Fri Apr 03 2009, 10:05 am
#2
Hi

PCF8574AP Port Expander is responding & it is giving ACK signal. Problam is with Pull up resisters (Vcc=3.3V), when I kept 10k pull up resisters device is not responding, I think bias current not sufficient for SCL &SDA Pins. When I kept 3.3K Resister devices is responding I think bias current sufficient for SCL &SDA Pins.

Regards
chandu
Sat Apr 04 2009, 01:55 am
#3
always 2k2 pullups when using highspeed and low power devices.
Sat Apr 04 2009, 05:20 pm
#4
Hi
I have interfaced 8 toggle switches to the PCF8574 I2C Port expander using LPC2114 Controller. I have to read the only one key status at time PCF8474 interrupt pin is connected to the External interrupt pin of the micro controller. In the External interrupt service routine I am enabling the Start bit of theI2C communication. Control will jump to the I2C interrupt routine and read the status of the I/O Pins & stops the I2C. But aim facing the problem with PCF8474 interrupts According to the PCF8474 data sheet; interrupt is generated by any rising or falling edge of the port inputs in the input mode.I/O pins are in high state, whenever press the switch it will go to low state, by releasing the pin will go to high state.
When ever I press the switch interrupt is generating in the high to low state and low to high state, beacaise of this I am reading the input pin status 0XFF (normally all pins are in high state). Whenever I press the each switch I am getting 0XFE(sw1), 0XFD(sw2), 0XFB(sw3), 0XF7(sw4), 0XEF(sw5), 0XDF(sw6), 0XBF(sw7), 0X7F(sw8) status for corresponding switch, whenever I release the switch I am getting 0xFF status for corresponding switches,
Please suggest how to solve the above problem

Regards
Chandu
Sun Apr 05 2009, 11:04 pm
#5
well this is how IO Expander has to work.. :-s
let me just put the things together to see more clearly the current problem..

you are able to read from IO Expander. Whenever you press a key you are getting perfect values. whenever you release key you get 0xFF.

am i right.. only thing is you are getting o/p for making and breaking of key isnt it? and you want to know how to overcome the 0xFF o/p just after the key is pressed? is it?
Fri Apr 10 2009, 06:01 pm
#6
Hi
Thanks for the reply
Yes u r right whenever I press a key I am getting perfect values. But whenever I release the key I am getting 0xFF value because any change in the I/O ports of the expander will generate the interrupt.
For each and every key there will be a corresponding action is there.
Please help me how to read the keys using PCF8574AP I/O Expander

Regards
Naresh
Sat Apr 11 2009, 02:41 pm
#7
I will take a small example for explaining this.

you have three keys connected at port pin 0,1 & 2

so when you press 0 you will get (0xFE)
for key 1 you will get (0xFD)
for key 2 you will get (0xFB)

so in your code you will do like this..
if( !(PORTData & 1) ){
    //key0 pressed
} else if(!(PORTData & 0x02)){
    //Key1 pressed
} else if (!(PORTData & 0x04)){
    //Key2 pressed
}

here Portdata is data received from IO Expander register.
when you run the code, when key is pressed the corresponding if loop with execute and when u get 0xFF no if loop get satisfied..

try it once.
Mon Apr 13 2009, 05:00 pm
#8
Thank You very Much

Now code is working properly ,I am getting proper key value for corresponding key

Regards
Naresh

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

AngeloFoown
Sat Apr 13 2024, 12:17 pm
JamesLex
Sat Apr 13 2024, 05:23 am
RobertWah
Fri Apr 12 2024, 08:01 pm
solar_qcor
Fri Apr 12 2024, 08:38 am
Rosalvascuth
Thu Apr 11 2024, 06:07 am
WilliamAmazy
Wed Apr 10 2024, 10:13 pm
slm_pkPn
Wed Apr 10 2024, 08:43 pm
LaurenBramn
Wed Apr 10 2024, 02:08 pm