I2C001 (v1.0.26) wrong documentation for I2C001_WriteData

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
Hi,

trying to develop a simple application with Dave3 (v3.1.18) for my XMC4500 Relax Kit using the I2C001 App (v1.0.26), I noted that the documentation of I2C001_WriteData seems to be not up to date.

This is the code snippet available for I2C001_WriteData in I2C001.h and in the online help:

#include
int main(void)
{

DAVE_Init();

// Configure message data length
I2C001_Type data1,data2,data3,data4;

// Write access IO expander device PCA9502
// Transmission by the master with start condition,
// I2C write condition and slave address
data1.TDF_Type = I2C_TDF_MStart;
data1.Data = (0x98 | I2C_WRITE);
I2C001_WriteData(&I2C001_Handle0,&data1);

// Write to the direction register
data2.TDF_Type = I2C_TDF_MTxData;
data2.Data = 0x50;
I2C001_WriteData(&I2C001_Handle0,&data2);

// Write data to configure one bit as output
data3.TDF_Type = I2C_TDF_MTxData;
data3.Data = 0x01;
I2C001_WriteData(&I2C001_Handle0,&data3);

// Stop condition by the master
data4.TDF_Type = I2C_TDF_MStop;
data4.Data = ubyteFF;
I2C001_WriteData(&I2C001_Handle0,&data4);

while(1)
{}
return 0;
}



I used this code as a base to develop my application (use of an I2C 3-axis accelerometer and magnetometer connected to XMC4500); however the compiler complains that the second argument passed to I2C001_WriteData instances is of the wrong type:



[...note: expected 'const union I2C001_DataType *' but argument is of type 'struct I2C001_Type *'
I]


So I wrote my code as follows:

uint8_t accelerometerConfigurationData[7] = {0xA0, 0x3F, 0x00, 0x00, ACCELEROMETER_FSR_INDEX << 4, 0x00, 0x00};
uint8_t magnetometerConfigurationData[4] = {0x00, 0x1c, MAGNETOMETER_FSR_INDEX << 5, 0x00};
I2C001_DataType I2CXmtData;
uint8_t k;

// Configure accelerometer
// Start
I2CXmtData.Data1.TDF_Type = I2C_TDF_MStart;
I2CXmtData.Data1.Data = (ACCELEROMETER_I2C_ADDRESS | I2C_WRITE);
I2C001_WriteData(&I2C001_Handle0, &I2CXmtData);

// Write to the accelerometer configuration registers
I2CXmtData.Data1.TDF_Type = I2C_TDF_MTxData;
for (k = 0; k < 7; k++) {
I2CXmtData.Data1.Data = accelerometerConfigurationData;
I2C001_WriteData(&I2C001_Handle0, &I2CXmtData);
}

// Stop
I2CXmtData.Data1.TDF_Type = I2C_TDF_MStop;
I2CXmtData.Data1.Data = 0xff;
I2C001_WriteData(&I2C001_Handle0, &I2CXmtData);

and it compiles correctly.

I think that it is necessary to correct this problem in the future releases of I2C001, because it generates confusion in users, especially those with limited experience.

Thank you
0 Likes
1 Reply
Not applicable
Hi Francesco,

Do you notice that the "I2C001_Example1" shows the correct usage and can be compiled without error. Perhaps Infineon just needs to correct the help documentation.

BR,
Zain
0 Likes