TPS65217 chip i2c register setting

Hi all,

I am trying to change some register settings for TPS6217 (power management chip) through i2c on linux userspace.

My hope is to configure the settings using c++. I am using the kernel 3.2.33, and the i2c slave address is already binded to the driver. (seems TPS65217 specific)

I know how to use i2c drivers for general i2c, But I don know how to include and use TPS65217 driver on my code. Any ideas?

Best regards,

Hi Jin,
I am looking at this post for information and would like to ask you how to read using i2c in c++.
I have the following code for write which works fine.

txBuffer[0] = 0x2a; // location to write data
txBuffer[1] = 0xfe ; //data
opResult = write(i2cFD, txBuffer, 2); //write statement.
if (opResult !=2) printf(“No ACK bit!\n”);

I am having issues with read. I have the following code

opResult = read(i2cFD, (char*)rxBuffer, 6);
printf(“Part ID rx0: %x, %x\n”, (int)rxBuffer[0], 0x00);
printf(“Part ID rx1: %x, %x\n”, (int)rxBuffer[1], 0x01);
printf(“Part ID rx2: %x, %x\n”, (int)rxBuffer[2], 0x02);
printf(“Part ID rx3: %x, %x\n”, (int)rxBuffer[3], 0x03);
printf(“Part ID rx4: %x, %x\n”, (int)rxBuffer[4], 0x04);

printf(“Part ID rx5: %x, %x\n”, (int)rxBuffer[5], 0x05);

It prints out different values then what I expect using i2cdump
Can you shed some light on my problem?
Thanks big time.


I am not sure exactly what issue you are experiencing, but here is my source code. Hope it helps.


batterygauge.cpp (4.66 KB)

batterygauge.h (1017 Bytes)

Hi Jinsuk,
Thank you for the support. I am a beginner myself but I will try to understand the code. My problem is if you look at (code.png) it is the code that is providing me the error. The code2 is the output that I am getting(erroneous). And code 3 is the output I should be getting. Somehow, the program is skipping even values after 0.
It would be a huge help to a beginner like me if you can glance at it and point me in the right direction.