Content originally posted in LPCWare by wongss on Fri May 31 21:45:48 MST 2013
Would like to make some comment here. I put it here as I am also currently struggling with i2c on lpc812:
I find the LPC8xx processor very attractive in price and performance. Unfortunately, I find the examples given very intimidating.
I have been struggling to get the i2c to work properly. It also currently freezes at the I2C_MstSend().
I had been using our own 3 functions (master mode) in our teaching and student projects using 8051 compatible controllers:
void i2cInit(void);
uint8_t i2cSend(uint8_t addr, uint8_t n, uint8_t *buf); // return success or failure
uint8_t i2cReceive(uint8_t addr, uint8_t n, uint8_t *buf); // return success or failure
None of the above would get stuck even if there will be error (e.g. nack).
We also use mbed. The i2c and spi functions are really easy to use and one can focus on the application.
Unfortunately, the nxp mbed boards are rather costly and the environment can be quick different when one moves to own target board.
I recently actively promote the use of Arduino environment on atmega328 MCU on breadboard to student projects.
We encapsulate the given i2c wire.h functions (already considered a bit complex) to the above 3 simple to use functions too.
I intend to use lpc8xx as either host or peripherals. Unfortunately the examples given put me off (sorry to say that).
They are hard to understand to me and there are lots of intimidating registers level access.
Documentation is poor, eg. there are inconsistencies and some of the input and output parameters are not even explained.
Example:
/*****************************************************************************
** Function name:I2C_MstInit
**
** Descriptions:I2C port initialization routine
**
** parameters:None
** Returned value:None
**
*****************************************************************************/
void I2C_MstInit( LPC_I2C_TypeDef *I2Cx, uint32_t div, uint32_t cfg, uint32_t dutycycle )
{
/* For master mode plus, if desired I2C clock is 1MHz (SCL high time + SCL low time).
If CCLK is 36MHz, MasterSclLow and MasterSclHigh are 0s,
SCL high time = (ClkDiv+1) * (MstSclHigh + 2 )
SCL low time = (ClkDiv+1) * (MstSclLow + 2 )
Pre-divider should be 8.
If fast mode, e.g. communicating with a temp sensor, Max I2C clock is set to 400KHz.
Pre-divider should be 11. */
There is no simple example to learn from. The i2ctest.c is hard to understand.
Just wander if it is possible for nxp to provide some easy to use basic functions so that we quickly focus on applications be successful quickly.
Not sure if the expectation is reasonable.