Hi,
I started learning to use the I2C function of LPC1769.
Could anyone provide me the sample program for the initialization and data transmission of I2C related registers?
I tried to create my code based on the information from the user's manual of 1769, but it is too complicated for me to understand exactly what kind of setting is correct. I also tried the sample code of LPCOPEN (sample code for using EEPROM) but it is also complicated too, and I even could not compile it.
What I would like to do is just
(1) initialize the I2C setting, and
(2) send binary signal from SDA pin (P0_28) like LOW, HIGH, LOW, HIGH... in parallel with the clock from SCL pin (P0_27).
I know the protocol of I2C and what kind of signal should be sent from the pins. I am not sure just how to adjust the register setting of LPC1769.
What I understood from the manual is that following setting may be required, but it might be incorrect;
<Initialization>
LPC_SC->PCONP |= (1 << 7); //Power on PCI2C0
LPC_SC->PCLKSEL0 |= (3 << 14); //Input clock to I2C0 (φ/8)
LPC_PINCON->PINSEL1 |= (1<<22); //P0_27 to SCL mode
LPC_PINCON->PINSEL1 &= ~(1<<23); //P0_27 to SCL mode
LPC_PINCON->PINSEL1 |= (1<<24); //P0_28 to SCL mode
LPC_PINCON->PINSEL1 &= ~(1<<25); //P0_28をSCL mode
LPC_I2C0->I2CONSET = 0x40; //enable I2C
LPC_I2C0->I2SCLH = 0x06;
LPC_I2C0->I2SCLL = 0x06;
...anything else?
<Data transmission>
I have no idea.
The support would be highly appreciated.
regards,
Hi Hitotsu,
If you want the sample code which is using the register mode, you can refer to the LPC17xx code bundle sample code, please find it from the attachment.
1. mdk project
mcb1700.code_.bundle.lpc17xx.keil_.zip
2. LPCxpresso IDE project
mcb1700.code_.bundle.lpc1769.lpcxpresso.zip
Take keil project as an example, you can find the i2c sample code in folder: mcb1700.code_.bundle.lpc17xx.keil_\keil_examples\I2C
Please refer to I2C0Init().
Wish it helps you!
If you still have question, please contact me!
Have a great day,
Jingjing
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Jingjing,
Thank you for your kind advice. I imported all the files&projects from "mcb1700.code_.bundle.lpc1769.lpcxpresso.zip" into the LPC Xpresso version 8.1.4. I tried to "build all" but an error message shows up and failed. The message says below;
c:/nxp/lpcxpresso_8.1.4_606/lpcxpresso/tools/bin/../lib/gcc/arm-none-eabi/5.2.1/../../../../arm-none-eabi/bin/ld.exe: cannot find -lCMSISv2_LPC17xx collect2.exe: error: ld returned 1 exit status
make: *** [I2C.axf] Error 1
Is any additional setting required or additional program has to be imported to build the project?
Though it might be useful just to see the sample source for initialization of I2C, I would like to see how it works if possible.
Hi Hitotsu,
Please follow these steps:
1. import CMSISv2_LPC17xx
2. modify Core_cm3.c
Please replace all the "=r" to "=&r" in file core_cm3.c and save it, then build the CMSISv2_LPC17xx.
3. import I2C project, and build it.
You will find the problem is sloved.
Have a great day,
Jingjing
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Jingjing,
Thank you very much for your explanation and sorry for my late reply!
Thanks to your information, I could successfully build the sample project after all. Although I did not yet complete the program of I2C communication, I can analyze the sample and will know how to use it!
Regards,
Hitotsu
Hi Hitotsu,
If you want make the I2C communication, you also need to add the I2C slave.
Then you can use the Logic Analyzer to check the I2C wave, what the problem caused the I2C communication failure, the master or the slave.
Any problem, you can let me know!
Have a great day,
Jingjing
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hello Jingjing
Thank you for sharing that code. I want to use its I2C driver to work with a RTC chip (DS3231).
I saw the example and the driver in https://community.nxp.com/servlet/JiveServlet/download/820007-391187/mcb1700.code_.bundle.lpc17xx.ke... but I'm kind of confused. How come the example didn't call the I2CStart() , I2CStop() functions?
How can I use this driver for DS3231 ? Do I need to call those functions or it's just enough to set the buffers I2CEngine() ?