Read SMBus Battery Voltage with CYW943907AEVAL1F

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

cross mob
MaFa_974161
Level 5
Level 5
100 sign-ins 50 replies posted 50 questions asked

Hello.

I bought CYW943907AEVAL1F.

I have to connect I2C interface (I use I2C_0 : pins 23, 25 of J6)

with intelligent battery that uses SMBus.

I have to read Battery Voltage.

For read the Battery Voltage I have to write a specific "command_code" and the read two words.

The Battery I2C address is 0001 011 ,

the "command_code" for read Voltage is 0x09 in mV.

 

The datasheet of the intelligent Battery states that you can read Word in this way

MaFa_974161_0-1614239983027.png

 

I write this routine :

/* i2c battery */

wiced_i2c_device_t i2c_battery;

/* setup 'i2c_battery' params */

i2c_battery.port = WICED_I2C_1;
i2c_battery.speed_mode = I2C_STANDARD_SPEED_MODE;
i2c_battery.flags = I2C_DEVICE_USE_DMA;
i2c_battery.address = 0x16 >> 1; // 0001 011 Smart Battery Data Specification V1.1 December 1998
i2c_battery.address_width = I2C_ADDRESS_WIDTH_7BIT;

/* init 'i2c_battery' i2c */

status = wiced_i2c_init ( &i2c_battery );

if ( status != WICED_SUCCESS )
{
WPRINT_APP_INFO( ("wiced_i2c_init 'i2c_battery' failed, status = %d\n", status) );
return;
}

uint8_t command_code = 0x09;

/* write command_code */

wiced_result = wiced_i2c_write ( &i2c_battery, WICED_I2C_START_FLAG, (void*)&command_code, 1U );

if ( wiced_result != WICED_SUCCESS )
{
WPRINT_APP_INFO( ("[##] wiced_i2c_write failed, status = %d\n", (int)wiced_result) );
return wiced_result;
}

/* read word */

wiced_result = wiced_i2c_read ( &i2c_battery, WICED_I2C_REPEATED_START_FLAG, (void*)&word, 2U );

if ( wiced_result != WICED_SUCCESS )
{
WPRINT_APP_INFO( ("[##] wiced_i2c_read failed, status = %d\n", (int)wiced_result) );
return wiced_result;

}

The code does't work because wiced_i2c_write fails with result 4 (WICED_ERROR).

The signals that I observe with scope are ...

2021-02-25_091540.png

 

What I'm wrong ?

The battery responds ACK for the Write command_code ...

 

0 Likes
1 Solution
MaFa_974161
Level 5
Level 5
100 sign-ins 50 replies posted 50 questions asked

OK, I solved the problem.

I downgrade I2C clock to I2C_LOW_SPEED_MODE.

Battery specification states max 100kHz of clock.

View solution in original post

0 Likes
6 Replies
MaFa_974161
Level 5
Level 5
100 sign-ins 50 replies posted 50 questions asked

In particular I don't understand why just wiced_i2c_write produces 3 clock cycles ...

2021-02-25_093353.png

 

0 Likes
Murali_R
Moderator
Moderator
Moderator
250 sign-ins 250 replies posted 100 solutions authored

Can you do a debug build and let me know the exact point at which this is failing and from which point the WICED_ERROR is being reported?

0 Likes
Aditi_B
Moderator
Moderator
Moderator
500 replies posted 5 questions asked 250 replies posted

Hi,

1. In the wiced_i2c_write API, you need to provide the WICED_I2C_STOP_FLAG as well with the WICED_I2C_START_FLAG In the I2C protocol, the stop condition have to be issued by the master at the end of the message frame. So, your API should look something like this-

wiced_i2c_write(&i2cDevice, WICED_I2C_START_FLAG | WICED_I2C_STOP_FLAG, tx_buffer, sizeof(tx_buffer));

2. The command code that you're sending (0x09), is this the value or the offset? As seen above the tx_buffer will contain an offset and then a single value, so we need 2 bytes in the buffer. So, you should be declaring a buffer and the first element of that buffer will be the offset and the next element would be the value. You can go through this I2C write implementation for getting  better picture- https://github.com/cypresssemiconductorco/CypressAcademy_WICED_WiFi101_Files/blob/master/Projects/ww...

I hope this helps!

Thanks

Aditi

0 Likes

But the datasheet of the intelligent Battery states that you have to:

 

1. write 0x09 byte without STOP flag

2. read two bytes (one word) 

 

0 Likes
lock attach
Attachments are accessible only for community members.
MaFa_974161
Level 5
Level 5
100 sign-ins 50 replies posted 50 questions asked

file i2c.c row 43, wiced_result = 4 ( WICED_ERROR )

0 Likes
MaFa_974161
Level 5
Level 5
100 sign-ins 50 replies posted 50 questions asked

OK, I solved the problem.

I downgrade I2C clock to I2C_LOW_SPEED_MODE.

Battery specification states max 100kHz of clock.

0 Likes