AnsweredAssumed Answered

LPC1549 I2C question

Question asked by Fabrizio Bordi on May 31, 2019
Latest reply on Jun 3, 2019 by Felipe García

Hello everyone,

I am a newbie in I2C so please be patient.

I am using the example code or the I2C master interrupt mode of LPCopen on the OM13056 Evalboard (LPC1549 processor).

I want to communicate with a LSM9DS1 gyroscope-accelerometer-magnetometer sensor.

With the functions of the examples I managed to establish the connection between the board and the sensor without errors. The problem is that I can't perform the write operations to the registers of the sensor (which I need to do) neither read some useful data because I think I can't understand the logic of the example code.


These are the two crucial example functions.

In the ReadTemperatureI2CM() when it is called SetupXferRecAndExecute(..) the first function argument is the slave address (previously defined), the second one I think is the sensor's temperature-register address, the third is the number of bytes to send, the fourth is where do the data (received from the slave) are saved, and the last is the number of bytes to receive.

If I run this code I always get this output on Realterm "Temperature read over I2C is 64 degrees C." It doesn't change even if I "heat" the sensor.

I think I have to initialize the sensor specification by doing some write operations to the sensor registers.

How can I write on a specific slave register? Is this "SetupXferRecAndExecute"

 funtion the one I need?


Thanks to everyone who will help me.


static void SetupXferRecAndExecute(uint8_t devAddr,uint8_t *txBuffPtr,uint16_t txSize,uint8_t *rxBuffPtr,uint16_t rxSize)
/* Setup I2C transfer record */
i2cmXferRec.slaveAddr = devAddr;
i2cmXferRec.status = 0;
i2cmXferRec.txSz = txSize;
i2cmXferRec.rxSz = rxSize;
i2cmXferRec.txBuff = txBuffPtr;
i2cmXferRec.rxBuff = rxBuffPtr;

Chip_I2CM_Xfer(LPC_I2C0, &i2cmXferRec);
/* Enable Master Interrupts */
/* Wait for transfer completion */
/* Clear all Interrupts */


static void ReadTemperatureI2CM(void)
uint8_t temperature;
uint8_t lm75TempRegisterAddress = (0x15);

/* Read LM75 temperature sensor */

/* The LM75 I2C bus address */

/* Transmit one byte, the LM75 temp register address */
&lm75TempRegisterAddress, 1,

/* Receive back two bytes, the contents of the temperature register */
&temperature, 2);

/* Test for valid operation */
if (i2cmXferRec.status == I2CM_STATUS_OK) {
/* Output temperature. */
DEBUGOUT("Temperature read over I2C is %d degrees C.\r\n",
(int) temperature);
else {
DEBUGOUT("Error %d reading temperature.\r\n", i2cmXferRec.status );