EmbeddedRelated.com
Forums

Need help setting up I2C on LPC2103

Started by Neil Jansen July 15, 2007
What's the easiest way to set up I2C on an LPC2103? NXP's app note
uses interrupts, but I really don't want to use them if I don't have
to. I'm not trying to do any error handling or anything, I just want
to send a few messages to an I2C chip. The LPC2000's seem to really
complicate this.

Can someone point me to some (simple) example code? I tried the
I2C_lib.zip in the file section, but it doesn't mention whether it
needs interrupts enabled or not. Also I had some nitpicks with it,
like how it set I2CxCONCLR to 0xFF, where the User Manual says not to
write one's to unused bits... I don't need to add more unknowns to
what I already have. If I do run it as-is, it sits in an infinite
loop waiting for SI to be set, right after the START bit is set.

My setup: ARM-ELF-GCC v4.1.1, Eclipse under Ubuntu Linux, ARM-USB-OCD
and USB-JTAGKEY-TINY debuggers, both under OpenOCD. I2C device in
this case is an LM4970, the ARM would be in master transmit only,
nothing needs to be received from the slave.

For that matter, is there a central source where GCC users can get
LPC2000 code to access peripherals, i.e. UART, PWM, etc.. or is
everyone writing this stuff by hand? I can't afford a real IDE, and
have been struggling through getting the hardware set up myself.
Finding some GCC-friendly code with proven I2C, PWM, UART, and timer
functions would be awesome.

Thanks,

Neil

An Engineer's Guide to the LPC2100 Series

--- In l..., "Neil Jansen" wrote:
>
> What's the easiest way to set up I2C on an LPC2103? NXP's app note
> uses interrupts, but I really don't want to use them if I don't have
> to. I'm not trying to do any error handling or anything, I just want
> to send a few messages to an I2C chip. The LPC2000's seem to really
> complicate this.

It's the I2C protocol that is complicated. Almost every fully
function implementaton will use a state machine and change state every
time the controller generates an interruptl.

It is possible to bit-bang I2C if your needs are trivial. Google for
'bit-banged I2C', there are a couple of thousand hits.

Try this app note for various drivers including I2C:
http://www.nxp.com/acrobat_download/applicationnotes/AN10369_1.pdf I
believe this is the I2C driver that I have been using. I may have
tweaked it a bit.

>
> Can someone point me to some (simple) example code? I tried the
> I2C_lib.zip in the file section, but it doesn't mention whether it
> needs interrupts enabled or not. Also I had some nitpicks with it,
> like how it set I2CxCONCLR to 0xFF, where the User Manual says not to
> write one's to unused bits... I don't need to add more unknowns to
> what I already have. If I do run it as-is, it sits in an infinite
> loop waiting for SI to be set, right after the START bit is set.

I2C_lib.zip is NOT interrupt driven. It is polled. So, it is a step
up from bit-banging.

>
> My setup: ARM-ELF-GCC v4.1.1, Eclipse under Ubuntu Linux, ARM-USB-OCD
> and USB-JTAGKEY-TINY debuggers, both under OpenOCD. I2C device in
> this case is an LM4970, the ARM would be in master transmit only,
> nothing needs to be received from the slave.
>
> For that matter, is there a central source where GCC users can get
> LPC2000 code to access peripherals, i.e. UART, PWM, etc.. or is
> everyone writing this stuff by hand? I can't afford a real IDE, and
> have been struggling through getting the hardware set up myself.
> Finding some GCC-friendly code with proven I2C, PWM, UART, and timer
> functions would be awesome.

Philips/NXP has produced code for many of their chips and there is a
lot of it floating around in this group. But I would expect that most
folks are writing their own. It only needs to be done once!

If you are thinking about an IDE or just want a step up, try James
Lynch's excellent tutorial:
http://www.olimex.com/dev/pdf/ARM%20Cross%20Development%20with%20Eclipse%20version%203.pdf

It will detail the installation of Eclipse as an IDE plus a plug-in
for C/C++ development and then it moves on to the rest of the tool
chain. Complete projects for the LPC2106 and LPC2148 are included.
Step by step... It certainly help me up the learning curve!

Richard
> Try this app note for various drivers including I2C:
> http://www.nxp.com/acrobat_download/applicationnotes/AN10369_1.pdf I
> believe this is the I2C driver that I have been using. I may have
> tweaked it a bit.

That's the appnote I was referring to. Just seems overkill to me but
Philips/NXP invented I2C so I see their reasons to implement it the
way they have.

> I2C_lib.zip is NOT interrupt driven. It is polled. So, it is a step
> up from bit-banging.

That's what I'm trying to do (poll SI until it goes high). But I
can't get this code to work after a few days of trying.

> Philips/NXP has produced code for many of their chips and there is a
> lot of it floating around in this group. But I would expect that most
> folks are writing their own. It only needs to be done once!

Exactly, it seems that everyone's writing their own instead of using
it from one source. I haven't found a decent tested library for
LPC2xxx that works with GCC. I'd take on setting up a project like
this but I'm new to ARM's and am not qualified at this point.

> If you are thinking about an IDE or just want a step up, try James
> Lynch's excellent tutorial:
>
http://www.olimex.com/dev/pdf/ARM%20Cross%20Development%20with%20Eclipse%20version%203.pdf
>
> It will detail the installation of Eclipse as an IDE plus a plug-in
> for C/C++ development and then it moves on to the rest of the tool
> chain. Complete projects for the LPC2106 and LPC2148 are included.
> Step by step... It certainly help me up the learning curve!

I did all this (I mentioned that I'm using Eclipse and GCC 4.1.1 that
I compiled from source). I even used a modified version of his CRT.s
startup file. He doesn't have any examples on I2C, and even if he
did, they wouldn't be for the LPC2103. I guess I'm on my own :(
I have some polling mode code that I just finished adding to my
LPC2148 demo package. If you'd like a copy to play with prior to the
release of the updated demo package, I'd be happy to send it to you
off-list.

I have wrappers for it to talk to a LM75 temperature sensors. It can
give you a framework how to use it.

--jc
--- In l..., "jcwren" wrote:
>
> I have some polling mode code that I just finished adding to my
> LPC2148 demo package. If you'd like a copy to play with prior to the
> release of the updated demo package, I'd be happy to send it to you
> off-list.
>
> I have wrappers for it to talk to a LM75 temperature sensors. It can
> give you a framework how to use it.
>
> --jc
>

Thanks, e-mail sent.
You can use I2C without interrupt. I am using for reading I/O expander and
EEPROM.
Setup I2C, write to I2CDAT and watch the watch the busy flag.
Its very simple.

Warm Regards,

Mukund Deshmukh,
Beta Computronics Pvt Ltd.
10/1 IT Park, Parsodi,
Nagpur -440022 India.
Web site - http://betacomp.com

MEET US AT,

K2007, Dusseldorf, Germany, Hall 12, Stall C36-2.

> What's the easiest way to set up I2C on an LPC2103? NXP's app note
> uses interrupts, but I really don't want to use them if I don't have
I tried that but couldn't get it working. Which busy flag are you
referring to? I was waiting for SI (I2C interrupt flag) to go high,
but I guess that only happens with initerrupts enabled.

--- In l..., "Mukund Deshmukh"
wrote:
>
> You can use I2C without interrupt. I am using for reading I/O
expander and
> EEPROM.
> Setup I2C, write to I2CDAT and watch the watch the busy flag.
> Its very simple.
>
> Warm Regards,
>
> Mukund Deshmukh,
> Beta Computronics Pvt Ltd.
> 10/1 IT Park, Parsodi,
> Nagpur -440022 India.
> Web site - http://betacomp.com
>
> MEET US AT,
>
> K2007, Dusseldorf, Germany, Hall 12, Stall C36-2.
> > What's the easiest way to set up I2C on an LPC2103? NXP's app note
> > uses interrupts, but I really don't want to use them if I don't have
>
I use

while( ! (I2CONSET & 0x8)); // wait till status available
to test the busy status of I2C, after writing to I2CDAT

Warm Regards,

Mukund Deshmukh,
Beta Computronics Pvt Ltd.
10/1 IT Park, Parsodi,
Nagpur -440022 India.
Web site - http://betacomp.com

MEET US AT,

K2007, Dusseldorf, Germany, Hall 12, Stall C36-2.

----- Original Message -----
From: "Neil Jansen"
To:
Sent: Sunday, July 15, 2007 11:57 PM
Subject: [lpc2000] Re: Need help setting up I2C on LPC2103
I tried that but couldn't get it working. Which busy flag are you
referring to? I was waiting for SI (I2C interrupt flag) to go high,
but I guess that only happens with initerrupts enabled.

--- In l..., "Mukund Deshmukh"
wrote:
>
> You can use I2C without interrupt. I am using for reading I/O
expander and
> EEPROM.
> Setup I2C, write to I2CDAT and watch the watch the busy flag.
> Its very simple.
>
> Warm Regards,
>
> Mukund Deshmukh,
> Beta Computronics Pvt Ltd.
> 10/1 IT Park, Parsodi,
> Nagpur -440022 India.
> Web site - http://betacomp.com
>
> MEET US AT,
>
> K2007, Dusseldorf, Germany, Hall 12, Stall C36-2.
> > What's the easiest way to set up I2C on an LPC2103? NXP's app note
> > uses interrupts, but I really don't want to use them if I don't have
>
You have to be careful with a simple test like this. With a timeout, if
there is a problem on the I2C bus you can be grind to a halt. Try
shorting the I2C SDA and SCL lines together for an example...

Mike
On Tue, 2007-07-17 at 14:22 -0700, Mukund Deshmukh wrote:
>
> I use
>
> while( ! (I2CONSET & 0x8)); // wait till status available
> to test the busy status of I2C, after writing to I2CDAT
>
> Warm Regards,
>
> Mukund Deshmukh,
> Beta Computronics Pvt Ltd.
> 10/1 IT Park, Parsodi,
> Nagpur -440022 India.
> Web site - http://betacomp.com
>
> MEET US AT,
>
> K2007, Dusseldorf, Germany, Hall 12, Stall C36-2.
>
> ----- Original Message -----
> From: "Neil Jansen"
> To:
> Sent: Sunday, July 15, 2007 11:57 PM
> Subject: [lpc2000] Re: Need help setting up I2C on LPC2103
>
> I tried that but couldn't get it working. Which busy flag are you
> referring to? I was waiting for SI (I2C interrupt flag) to go high,
> but I guess that only happens with initerrupts enabled.
>
> --- In l..., "Mukund Deshmukh"
> wrote:
> >
> > You can use I2C without interrupt. I am using for reading I/O
> expander and
> > EEPROM.
> > Setup I2C, write to I2CDAT and watch the watch the busy flag.
> > Its very simple.
> >
> >
> >
> > Warm Regards,
> >
> > Mukund Deshmukh,
> > Beta Computronics Pvt Ltd.
> > 10/1 IT Park, Parsodi,
> > Nagpur -440022 India.
> > Web site - http://betacomp.com
> >
> > MEET US AT,
> >
> > K2007, Dusseldorf, Germany, Hall 12, Stall C36-2.
> >
> >
> >
> >
> > > What's the easiest way to set up I2C on an LPC2103? NXP's app note
> > > uses interrupts, but I really don't want to use them if I don't
> have
> >
>
Sorry, should have been "without a timeout"

Mike
On Mon, 2007-07-16 at 06:53 -0600, Mike Cruse wrote:
> You have to be careful with a simple test like this. With a timeout,
> if
> there is a problem on the I2C bus you can be grind to a halt. Try
> shorting the I2C SDA and SCL lines together for an example...
>
> Mike
>
> On Tue, 2007-07-17 at 14:22 -0700, Mukund Deshmukh wrote:
> >
> > I use
> >
> > while( ! (I2CONSET & 0x8)); // wait till status available
> > to test the busy status of I2C, after writing to I2CDAT
> >
> > Warm Regards,
> >
> > Mukund Deshmukh,
> > Beta Computronics Pvt Ltd.
> > 10/1 IT Park, Parsodi,
> > Nagpur -440022 India.
> > Web site - http://betacomp.com
> >
> > MEET US AT,
> >
> > K2007, Dusseldorf, Germany, Hall 12, Stall C36-2.
> >
> > ----- Original Message -----
> > From: "Neil Jansen"
> > To:
> > Sent: Sunday, July 15, 2007 11:57 PM
> > Subject: [lpc2000] Re: Need help setting up I2C on LPC2103
> >
> > I tried that but couldn't get it working. Which busy flag are you
> > referring to? I was waiting for SI (I2C interrupt flag) to go high,
> > but I guess that only happens with initerrupts enabled.
> >
> > --- In l..., "Mukund Deshmukh"
> > wrote:
> > >
> > > You can use I2C without interrupt. I am using for reading I/O
> > expander and
> > > EEPROM.
> > > Setup I2C, write to I2CDAT and watch the watch the busy flag.
> > > Its very simple.
> > >
> > >
> > >
> > > Warm Regards,
> > >
> > > Mukund Deshmukh,
> > > Beta Computronics Pvt Ltd.
> > > 10/1 IT Park, Parsodi,
> > > Nagpur -440022 India.
> > > Web site - http://betacomp.com
> > >
> > > MEET US AT,
> > >
> > > K2007, Dusseldorf, Germany, Hall 12, Stall C36-2.
> > >
> > >
> > >
> > >
> > > > What's the easiest way to set up I2C on an LPC2103? NXP's app
> note
> > > > uses interrupts, but I really don't want to use them if I don't
> > have
> > >
> >
> >
> >
> >
> >
>