code for I2C in lpc2106 using Keil.
2004-11-22 by jha_santosh_kr2005
Yahoo Groups archive
Index last updated: 2026-04-28 23:31 UTC
Thread
2004-11-22 by jha_santosh_kr2005
Hi, I am desperately trying to communicate with RTC pCF8583 using I2C of lpc2106 using Keil C compiler.But I am unable to start the I2C. Pl. help if u have time. Regards, Santosh Jha
2004-11-22 by zpierre007
Have you try the code source witch i put in the Files section : I2C.zip ? --- In lpc2000@yahoogroups.com, "jha_santosh_kr2005" <jha_santosh_kr2005@y...> wrote: > > Hi, > I am desperately trying to communicate with RTC pCF8583 using I2C of
> lpc2106 using Keil C compiler.But I am unable to start the I2C. > > Pl. help if u have time. > Regards, > Santosh Jha
2004-11-22 by peterburdine
--- In lpc2000@yahoogroups.com, "jha_santosh_kr2005"
<jha_santosh_kr2005@y...> wrote:
>
> Hi,
> I am desperately trying to communicate with RTC pCF8583 using I2C of
> lpc2106 using Keil C compiler.But I am unable to start the I2C.
>
> Pl. help if u have time.
> Regards,
> Santosh Jha
Here is an outline of a polled i2c function, there is more that goes
around this, but you can probably figure the rest out:
#define I2CONSET (*((volatile unsigned char *) 0xE001C000))
#define I2STAT (*((volatile unsigned char *) 0xE001C004))
#define I2DAT (*((volatile unsigned char *) 0xE001C008))
#define I2ADR (*((volatile unsigned char *) 0xE001C00C))
#define I2SCLH (*((volatile unsigned short*) 0xE001C010))
#define I2SCLL (*((volatile unsigned short*) 0xE001C014))
#define I2CONCLR (*((volatile unsigned char *) 0xE001C018))
#define ENABLE_I2C_PINS ( PINSEL0 = ((PINSEL0&0xFFFFFF0F) |
PINSEL0_02_SCL | PINSEL0_03_SDA ) )
#define ENABLE_I2C_IRQ ( VICIntEnable = (0x1 << I2C_IRQ) )
#define DISABLE_I2C_IRQ ( VICIntEnClr = (0x1 << I2C_IRQ) )
#define ENABLE_I2C_AA ( I2CONSET |= (0x1 << 2))
#define DISABLE_I2C_AA ( I2CONCLR = (0x1 << 2))
#define I2C_BIT_RATE(rate) (I2SCLH = I2SCLL =
((Uint16)(PERIPH_FREQ/2/rate)+10))
#define I2C_SEND_START (I2CONSET |= (0x1 << 5))
#define I2C_SEND_STOP (I2CONSET = (0x1 << 4))
#define I2C_CLR_START (I2CONCLR = (0x1 << 5))
#define I2C_CLR_SI (I2CONCLR = (0x1 << 3))
void i2c_transfer (void) {
Uint8 code;
Uint8 transferComplete = 0;
i2c_pos = 0;
while(!transferComplete) {
code = I2STAT;
switch(code) {
/***** MASTER TX MODE *****/
case 0x08: // First Start Transmitted
case 0x10: // Repeated Start
// Write address and tell if it is read or write
I2DAT = (i2c_address << 1) | i2c_RdnWr;
I2CONCLR = (0x1 << 3); // Clear SI
break;
case 0x18: // Start + Wr sent, ACK received
case 0x20: // Start + Wr sent, Not ACK received
case 0x28: // Data byte sent, ACK recieved
case 0x30: // Data byte sent, Not Ack received
if(i2c_bytesRemaining > 0) {
I2DAT = i2c_buffer[i2c_pos++];
i2c_bytesRemaining--;
I2CONCLR = (0x1 << 5);
}
else if(i2c_rxBytesRemaining == 0) {
I2C_SEND_STOP; // Send Stop
I2CONCLR = (0x1 << 5);
transferComplete = 1;
}
else { // Change from master_tx to master_rx
i2c_RdnWr = (~i2c_RdnWr)&0x1;
i2c_pos = 0;
i2c_rxWrPos = 0;
i2c_rxComplete = 0;
I2C_SEND_START;
}
I2CONCLR = (0x1 << 3); // Clear SI
break;
case 0x38: // Arbitration Lost, try again
I2C_SEND_START;
I2CONCLR = (0x1 << 3); // Clear SI
break;
/***** MASTER RX MODE *****/
case 0x40: // SLA+R HAS BEEN SENT; ACK RECEIVED
if(i2c_rxBytesRemaining != 0)
ENABLE_I2C_AA;
else
DISABLE_I2C_AA;
I2CONCLR = (0x1 << 3) | (0x1 << 5); // Clear SI and START
break;
case 0x48: // SLA+R has been send; not ack received
// Try again
I2C_SEND_START;
I2C_CLR_SI;
break;
case 0x50: // DATA BYTE RECEIVED, ACK RETURNED
i2c_rxBuffer[i2c_rxWrPos] = I2DAT;
i2c_rxWrPos++;
i2c_rxBytesRemaining--;
if(i2c_rxBytesRemaining != 0)
ENABLE_I2C_AA;
else
DISABLE_I2C_AA;
I2CONCLR = (0x1 << 3) | (0x1 << 5); // Clear SI and START
break;
case 0x58: // DATA BYTE RECEIVED; NOT ACT RETURNED
i2c_rxComplete = 1; // Done receiving all requested data
transferComplete = 1;
I2C_CLR_START;
I2C_SEND_STOP;
I2C_CLR_SI;
break;
}
}
}2004-11-23 by santosh jha
hi
just after initialisation of I2c if i send a data then waveform should be observed at SCD/SDA even if there is no I2C device connected. am I right?
I donot get any waveform.
Santosh Jha
peterburdine <lordofdawn@hotmail.com> wrote:
--- In lpc2000@yahoogroups.com, "jha_santosh_kr2005"
<jha_santosh_kr2005@y...> wrote:
>
> Hi,
> I am desperately trying to communicate with RTC pCF8583 using I2C of
> lpc2106 using Keil C compiler.But I am unable to start the I2C.
>
> Pl. help if u have time.
> Regards,
> Santosh Jha
Here is an outline of a polled i2c function, there is more that goes
around this, but you can probably figure the rest out:
#define I2CONSET (*((volatile unsigned char *) 0xE001C000))
#define I2STAT (*((volatile unsigned char *) 0xE001C004))
#define I2DAT (*((volatile unsigned char *) 0xE001C008))
#define I2ADR (*((volatile unsigned char *) 0xE001C00C))
#define I2SCLH (*((volatile unsigned short*) 0xE001C010))
#define I2SCLL (*((volatile unsigned short*) 0xE001C014))
#define I2CONCLR (*((volatile unsigned char *) 0xE001C018))
#define ENABLE_I2C_PINS ( PINSEL0 = ((PINSEL0&0xFFFFFF0F) |
PINSEL0_02_SCL | PINSEL0_03_SDA ) )
#define ENABLE_I2C_IRQ ( VICIntEnable = (0x1 << I2C_IRQ) )
#define DISABLE_I2C_IRQ ( VICIntEnClr = (0x1 << I2C_IRQ) )
#define ENABLE_I2C_AA ( I2CONSET |= (0x1 << 2))
#define DISABLE_I2C_AA ( I2CONCLR = (0x1 << 2))
#define I2C_BIT_RATE(rate) (I2SCLH = I2SCLL =
((Uint16)(PERIPH_FREQ/2/rate)+10))
#define I2C_SEND_START (I2CONSET |= (0x1 << 5))
#define I2C_SEND_STOP (I2CONSET = (0x1 << 4))
#define I2C_CLR_START (I2CONCLR = (0x1 << 5))
#define I2C_CLR_SI (I2CONCLR = (0x1 << 3))
void i2c_transfer (void) {
Uint8 code;
Uint8 transferComplete = 0;
i2c_pos = 0;
while(!transferComplete) {
code = I2STAT;
switch(code) {
/***** MASTER TX MODE *****/
case 0x08: // First Start Transmitted
case 0x10: // Repeated Start
// Write address and tell if it is read or write
I2DAT = (i2c_address << 1) | i2c_RdnWr;
I2CONCLR = (0x1 << 3); // Clear SI
break;
case 0x18: // Start + Wr sent, ACK received
case 0x20: // Start + Wr sent, Not ACK received
case 0x28: // Data byte sent, ACK recieved
case 0x30: // Data byte sent, Not Ack received
if(i2c_bytesRemaining > 0) {
I2DAT = i2c_buffer[i2c_pos++];
i2c_bytesRemaining--;
I2CONCLR = (0x1 << 5);
}
else if(i2c_rxBytesRemaining == 0) {
I2C_SEND_STOP; // Send Stop
I2CONCLR = (0x1 << 5);
transferComplete = 1;
}
else { // Change from master_tx to master_rx
i2c_RdnWr = (~i2c_RdnWr)&0x1;
i2c_pos = 0;
i2c_rxWrPos = 0;
i2c_rxComplete = 0;
I2C_SEND_START;
}
I2CONCLR = (0x1 << 3); // Clear SI
break;
case 0x38: // Arbitration Lost, try again
I2C_SEND_START;
I2CONCLR = (0x1 << 3); // Clear SI
break;
/***** MASTER RX MODE *****/
case 0x40: // SLA+R HAS BEEN SENT; ACK RECEIVED
if(i2c_rxBytesRemaining != 0)
ENABLE_I2C_AA;
else
DISABLE_I2C_AA;
I2CONCLR = (0x1 << 3) | (0x1 << 5); // Clear SI and START
break;
case 0x48: // SLA+R has been send; not ack received
// Try again
I2C_SEND_START;
I2C_CLR_SI;
break;
case 0x50: // DATA BYTE RECEIVED, ACK RETURNED
i2c_rxBuffer[i2c_rxWrPos] = I2DAT;
i2c_rxWrPos++;
i2c_rxBytesRemaining--;
if(i2c_rxBytesRemaining != 0)
ENABLE_I2C_AA;
else
DISABLE_I2C_AA;
I2CONCLR = (0x1 << 3) | (0x1 << 5); // Clear SI and START
break;
case 0x58: // DATA BYTE RECEIVED; NOT ACT RETURNED
i2c_rxComplete = 1; // Done receiving all requested data
transferComplete = 1;
I2C_CLR_START;
I2C_SEND_STOP;
I2C_CLR_SI;
break;
}
}
}
Yahoo! Groups SponsorADVERTISEMENT
---------------------------------
Yahoo! Groups Links
To visit your group on the web, go to:
http://groups.yahoo.com/group/lpc2000/
To unsubscribe from this group, send an email to:
lpc2000-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
---------------------------------
Do you Yahoo!?
Discover all that�s new in My Yahoo!
[Non-text portions of this message have been removed]2004-11-23 by santosh jha
Hi Zpierre, this code worked greatly. Thanx. Santosh Jha zpierre007 <zpierre007@...> wrote: Have you try the code source witch i put in the Files section : I2C.zip ? --- In lpc2000@yahoogroups.com, "jha_santosh_kr2005" <jha_santosh_kr2005@y...> wrote: > > Hi, > I am desperately trying to communicate with RTC pCF8583 using I2C of > lpc2106 using Keil C compiler.But I am unable to start the I2C. > > Pl. help if u have time. > Regards, > Santosh Jha Yahoo! Groups SponsorADVERTISEMENT --------------------------------- Yahoo! Groups Links To visit your group on the web, go to: http://groups.yahoo.com/group/lpc2000/ To unsubscribe from this group, send an email to: lpc2000-unsubscribe@yahoogroups.com Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. --------------------------------- Do you Yahoo!? The all-new My Yahoo! � Get yours free! [Non-text portions of this message have been removed]
2004-11-23 by Richard
Assuming that you have pullups on the I2C lines........... --- In lpc2000@yahoogroups.com, santosh jha <jha_santosh_kr2005@y...> wrote: > Hi Zpierre, > this code worked greatly. > Thanx. > Santosh Jha > > > zpierre007 <zpierre007@y...> wrote: > > Have you try the code source witch i put in the Files section : > I2C.zip ? > > > > --- In lpc2000@yahoogroups.com, "jha_santosh_kr2005" > <jha_santosh_kr2005@y...> wrote: > > > > Hi, > > I am desperately trying to communicate with RTC pCF8583 using I2C > of > > lpc2106 using Keil C compiler.But I am unable to start the I2C. > > > > Pl. help if u have time. > > Regards, > > Santosh Jha > > > > > Yahoo! Groups SponsorADVERTISEMENT > > > --------------------------------- > Yahoo! Groups Links > > To visit your group on the web, go to: > http://groups.yahoo.com/group/lpc2000/ > > To unsubscribe from this group, send an email to: > lpc2000-unsubscribe@yahoogroups.com > > Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
> > > > --------------------------------- > Do you Yahoo!? > The all-new My Yahoo! Get yours free! > > [Non-text portions of this message have been removed]
2004-11-23 by zpierre007
Yes, 2 of 4.7k, connected to +Vcc, --- In lpc2000@yahoogroups.com, "Richard" <richas@y...> wrote:
> > Assuming that you have pullups on the I2C lines........... > > > > > --- In lpc2000@yahoogroups.com, santosh jha > <jha_santosh_kr2005@y...> wrote: > > Hi Zpierre, > > this code worked greatly. > > Thanx. > > Santosh Jha > > > > > > zpierre007 <zpierre007@y...> wrote: > > > > Have you try the code source witch i put in the Files section : > > I2C.zip ? > > > > > > > > --- In lpc2000@yahoogroups.com, "jha_santosh_kr2005" > > <jha_santosh_kr2005@y...> wrote: > > > > > > Hi, > > > I am desperately trying to communicate with RTC pCF8583 using > I2C > > of > > > lpc2106 using Keil C compiler.But I am unable to start the I2C. > > > > > > Pl. help if u have time. > > > Regards, > > > Santosh Jha > > > > > > > > > > Yahoo! Groups SponsorADVERTISEMENT > > > > > > --------------------------------- > > Yahoo! Groups Links > > > > To visit your group on the web, go to: > > http://groups.yahoo.com/group/lpc2000/ > > > > To unsubscribe from this group, send an email to: > > lpc2000-unsubscribe@yahoogroups.com > > > > Your use of Yahoo! Groups is subject to the Yahoo! Terms of > Service. > > > > > > > > --------------------------------- > > Do you Yahoo!? > > The all-new My Yahoo! Get yours free! > > > > [Non-text portions of this message have been removed]