EmbeddedRelated.com
Forums
Memfault Beyond the Launch

LPC2148 and I2C connection to MCP23017

Started by nickdesantis54 February 20, 2013
Hi guys and gals, I'm working on a a project where I want to interface an LPC2148 with 16 MCP23017 I/O Expanders via the two I2C buses. The 2148 obviously runs on 3.3V and the MCP23017s will run on 5v, so I'm wondering if SCL and SDA will definitely need to be connected to 5v with a pull up resistor. Besides that, could anyone point me in a good direction for learning how to work with the I2C connection? I'd like to see some sample code on how to initialize and work with I2C.

Any help is much appreciated!

An Engineer's Guide to the LPC2100 Series

@nick : You can try running the system on 3V3. In my experience multiple
times the TTL devices run perfectly fine at CMOS voltages.
If that doesn't work out LPC2148 i/o pins are 5V tolerant so the 5V pull up
should not create a problem in my opinion.

I2C protocol varies a little from device to device. It would be good if you
go through the datasheet of MCP carefully specially the message format and
its figures. It would be wise to use some I2C sample code and modify it
according to your device. Try the Keil CA ARM Examples they are clear and
god for modifications.
On Wed, Feb 20, 2013 at 8:27 AM, nickdesantis54 wrote:

> **
> Hi guys and gals, I'm working on a a project where I want to interface an
> LPC2148 with 16 MCP23017 I/O Expanders via the two I2C buses. The 2148
> obviously runs on 3.3V and the MCP23017s will run on 5v, so I'm wondering
> if SCL and SDA will definitely need to be connected to 5v with a pull up
> resistor. Besides that, could anyone point me in a good direction for
> learning how to work with the I2C connection? I'd like to see some sample
> code on how to initialize and work with I2C.
>
> Any help is much appreciated!
>
>
>

--
Shashank Maheshwari


On Wed, 2013-02-20 at 02:57 +0000, nickdesantis54 wrote:
> Hi guys and gals, I'm working on a a project where I want to
> interface an LPC2148 with 16 MCP23017 I/O Expanders via the
> two I2C buses. The 2148 obviously runs on 3.3V and the
> MCP23017s will run on 5v, so I'm wondering if SCL and SDA
> will definitely need to be connected to 5v with a pull up
> resistor.

The lpc2148 datasheet mentions 5V tolerant IO pins and other
IO pins with 4.6V maximum. It might be safer to have some
level translation on the i2c bus lines, search with google
for "level translation i2c", app note an97055.
Or part number pca9306 :
http://www.nxp.com/documents/data_sheet/PCA9306.pdf
> Besides that, could anyone point me in a good
> direction for learning how to work with the I2C connection?
>
> I'd like to see some sample code on how to initialize and
> work with I2C.

Have a look here : http://www.jcwren.com/arm/

Further, this next "gadget" is a life saver :
http://www.saleae.com/logic
The application runs on Linux (and mac os) :-D

roelof

You should check the datasheet of the MCP23017 to see what voltage is considered a high and which a low. If you do need to use a 5v pullup, check whether or not the LPC pins are 5v tolerant.

If I am not mistaken the I2C is the same in the entire LPC2000 series (only the base address changes). Therefore most examples will do, which also depends on which IDE/compile you use.

--
Kevin
--- In l..., "nickdesantis54" wrote:
>
> Hi guys and gals, I'm working on a a project where I want to interface an LPC2148 with 16 MCP23017 I/O Expanders via the two I2C buses. The 2148 obviously runs on 3.3V and the MCP23017s will run on 5v, so I'm wondering if SCL and SDA will definitely need to be connected to 5v with a pull up resistor. Besides that, could anyone point me in a good direction for learning how to work with the I2C connection? I'd like to see some sample code on how to initialize and work with I2C.
>
> Any help is much appreciated!
>

Il 20/02/2013 03:57, nickdesantis54 ha scritto:
>
>
> Hi guys and gals, I'm working on a a project where I want to interface
> an LPC2148 with 16 MCP23017 I/O Expanders via the two I2C buses. The
> 2148 obviously runs on 3.3V and the MCP23017s will run on 5v, so I'm
> wondering if SCL and SDA will definitely need to be connected to 5v
> with a pull up resistor. Besides that, could anyone point me in a good
> direction for learning how to work with the I2C connection? I'd like
> to see some sample code on how to initialize and work with I2C.
>
LPC2148 I/Os are 5V tolerant so there is no problem for the inputs.
MCP23017 can work with VDD between 1.8V and 5.5V with an HIGH level at
0.8*VDD and LPC2148 HIGH at VDD-0.4V so:
MCP23017: 0.8*3.3 = 2.64
LPC2148: 3.3-0.4 = 2.9

this means that LPC2148 should have an HIGH level higher then minimum
HIGH level for MCP23017 so they should be compatible at VDD =3.3V
> Any help is much appreciated!



--- In l..., "nickdesantis54" wrote:
>
> Hi guys and gals, I'm working on a a project where I want to interface an LPC2148 with 16 MCP23017 I/O Expanders via the two I2C buses. The 2148 obviously runs on 3.3V and the MCP23017s will run on 5v, so I'm wondering if SCL and SDA will definitely need to be connected to 5v with a pull up resistor. Besides that, could anyone point me in a good direction for learning how to work with the I2C connection? I'd like to see some sample code on how to initialize and work with I2C.
>
> Any help is much appreciated!
>

You can Google for the I2C Specifications. NXP wrote it...

I2C is a PITA. If you aren't locked in, consider using the SPI variant of the IO Expanders instead.

You can find sample I2C code all over the place. Google for it.
Here's one example:
http://code.google.com/p/tauembedded/source/browse/trunk/exercise4/i2c/i2c.c?r

Here's another:
http://www.nxp.com/documents/application_note/AN10369.pdf

Basically, you send a START condition and from that point on, you will be receiving a series of interrupts. The interrupt handler implements a state machine for sending the various parts of the frame.

You can implement the state machine without using interrupts but the idea is the same.

You might find this useful:
http://f1.grp.yahoofs.com/v1/QN0nUWKju0ChXbVmm3XIQl_IznnrbfLdJX8wmQOaltUNwEFb5irUdrGxvdfReq4z4WWzX8qQ-4-kXP2kChd-RAaSWAowo8x3SCPCW1FHIV52TQ/I2C/I2C_Transaction_Summary.pdf

There is sample code in the Files folder for this group.

One thing you need to realize is that the actual transaction protocol is different for each type of device. So, sometimes the library code is very device specific.

Richard

If you read the datasheet (not the user manual) for the LPC2148, you will see that the I2C clock and data lines are specifically 5V tolerant. In I2C mode, they are open drain so pull-up resistors are required. I suggest something like 2.2k

Richard


Memfault Beyond the Launch