Simple example LPCOpen I2C

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Simple example LPCOpen I2C

5,183 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rosfudum on Fri Apr 17 03:05:30 MST 2015
Hi all,

I need to read/write an M24C16 Eeprom with LPC1115 using LPCOpen.

I read I2c example but it's pretty complicated.
It use Master and slave mode, and more than one peripheral.


I really was not able to understand in simply way how I2C works in LPCOpen.


Is there anyone has a just simply routine to write a data inside eeprom and read it as well?

I just need something like

I2C_Init()
I2C_send(data)
data = I2C_read();

Nothing more.
Thank you soooo much.
I'm spending so much time with no success at all.

Can you help me, please?
Labels (1)
0 Kudos
6 Replies

2,228 Views
miroslav_zinaic
Contributor I

I am using LPC11C24 and there you need to call

Chip_SYSCTL_DeassertPeriphReset(RESET_I2C0);

in order to use I2C bus. Apparently peripherial is in reset state until you deassert it, it was frustrating experinece because there in no mention of this in examples.

0 Kudos

2,228 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by dandumit on Sun Sep 20 22:05:00 MST 2015
Hello,
thank you for your example.
I have tried to use it on a LPC1769 with a 24c04.
When I call Chip_I2C_MasterSend or Chip_I2C_MasterRead it returns me number of bytes transferred.

Unfortunately all the bytes received are only 0xFF (255).

Any hints ?

thank you
Daniel
0 Kudos

2,228 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by dariush_abbasi868 on Tue Aug 04 06:23:00 MST 2015
When I try in LPCOPEN sample the function "Chip_I2C_MasterRead(i2cDev, xfer.slaveAddr, xfer.rxBuff, xfer.rxSz)"
always return 0 .
It means that nothing received !
actually I am testing it by ds1307 ( only for test to know is it OK or not)

xfer.slaveAddr = 0xd0;
xfer.rxBuff =rx;
xfer.rxSz = 1;

tx[0] = 0x01;
xfer.txSz = 1;
xfer.txBuff =tx;

xfer.slaveAddr=0xd0;
xfer.rxBuff = rx;
 xfer.rxSz = 2;
 Chip_I2C_MasterSend(i2cDev, xfer.slaveAddr, xfer.txBuff, xfer.txSz);
 Chip_I2C_MasterRead(i2cDev, xfer.slaveAddr, xfer.rxBuff, xfer.rxSz);


I want to read only at the moment.
0 Kudos

2,229 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by dariush_abbasi868 on Tue Aug 04 02:59:23 MST 2015
Hi
would you please send me a simple example that can read and write data exactly ?
I mean what I have to send and what i can receive ?
I know that in at24c512 for read I have to follow this step :

i2c_start();
i2c_write(ex_e2_add);                                     //i2c address of 24cxx series
 i2c_write(addressh);       //for extenal e2prom (24c512)  {heigh byte of addres}
i2c_write(addressl);                             //low byte of address
i2c_start();
i2c_write(ex_e2_add|0x01);                                  //low byte of address + one
bcc=i2c_read(0);
i2c_stop();

that ex_e2_add is 0xa0 .
how I can do it by your sample ?


0 Kudos

2,229 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rosfudum on Fri Apr 17 09:31:39 MST 2015
Thank you very much!

Your support is precious.
That simple project helped me a lot.

Thanks again
0 Kudos

2,229 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nerd herd on Fri Apr 17 08:24:17 MST 2015
Hi Rosfudum,

The example is a bit complicated since we setup our own "virtual" slave EEPROMs to be able to mimic I2C send and receives. What LPCOpen code base are you using? I took the LPCOpen for the LPC1125 and stripped down the i2c.c source file to only setup the I2C bus with example send/receive functions. Unfortunately I do not have hardware to test it, but I am fairly confident that it should work (I ported it from a stripped down example for the LPC11U24 so there is the possibility of the misuse of a variable in the chip or board libraries, but we can cross the bridge if we get there). Please replace your entire i2c.c source file with the one provided below:

http://pastebin.com/g90fJxY8

Let me know if you have any questions. Here is a link to the LPCOpen LPC1125 I used:

http://www.lpcware.com/content/nxpfile/lpcopen-software-development-platform-lpc11xx-packages-0
0 Kudos