LPC1549 I2C question

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

LPC1549 I2C question

774 Views
fabrizio_bordi
Contributor I

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 */
Chip_I2C_EnableInt(LPC_I2C0, I2C_INTENSET_MSTPENDING | I2C_INTENSET_MSTRARBLOSS | I2C_INTENSET_MSTSTSTPERR);
/* Wait for transfer completion */
WaitForI2cXferComplete(&i2cmXferRec);
/* Clear all Interrupts */
Chip_I2C_ClearInt(LPC_I2C0, I2C_INTENSET_MSTPENDING | I2C_INTENSET_MSTRARBLOSS | I2C_INTENSET_MSTSTSTPERR);
}

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

/* Read LM75 temperature sensor */
SetupXferRecAndExecute(

/* The LM75 I2C bus address */
I2C_TEMP_ADDR_7BIT,

/* 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 );
}
}

Labels (1)
Tags (3)
0 Kudos
1 Reply

585 Views
FelipeGarcia
NXP Employee
NXP Employee

Hi Fabrizio,

 

As you mention, those are functions you have to pay attention to in order to write to a specific register in your sensor. I recommend you to check on the sensor side of there is any initialization needed in order to start sensing the temperature.

 

Best regards,

Felipe

0 Kudos