Skip to main content
ssena.1514
Associate III
October 6, 2023
Solved

I2C read & write operation for LTC4015

  • October 6, 2023
  • 1 reply
  • 1097 views

 

Hi,

Currently I am working on a stm32 & LTC4015 based smart charger project.

 

When I followed the data sheet the smbus or i2c read & write operation is given as below:-

SMBus WRITE WORD PROTOCOL:-
S SLAVE ADDRESS Wr A COMMAND CODE A DATA BYTE LOW A DATA BYTE HIGH A P
SMBus WRITE WORD WITH PEC PROTOCOL
S SLAVE ADDRESS Wr A COMMAND CODE A DATA BYTE LOW A DATA BYTE HIGH A PEC* A P


SMBus READ WORD PROTOCOL:-
S SLAVE ADDRESS Wr A COMMAND CODE A Sr SLAVE ADDRESS Rd A DATA BYTE LOW A DATA BYTE HIGH N P
SMBus READ WORD WITH PEC PROTOCOL
S SLAVE ADDRESS Wr A COMMAND CODE A Sr SLAVE ADDRESS Rd A DATA BYTE LOW A DATA BYTE HIGH A PEC* N P
SMBus ALERT RESPONSE ADDRESS PROTOCOL
S ALERT RESPONSE ADDRESS Rd A DEVICE ADDRESS Rd N P
SMBus ALERT RESPONSE ADDRESS PROTOCOL WITH PEC
S ALERT RESPONSE ADDRESS Rd A DEVICE ADDRESS Rd A PEC* N

 

And I am reading from ltc4015 registers like this :-

ret = HAL_I2C_Mem_Read(&hi2c1,LTC4015_DEVICE_ADDRESS_READ,0x03,I2C_MEMADD_SIZE_8BIT,(uint16_t*)(&register_value2), 2, HAL_MAX_DELAY);

if (ret != HAL_OK)

{

Error_Handler();

}

 

and for writing:-

//Enable limit alerts

uint8_t dataBuffer0[2] = {0xBF,0xF0};

ret = HAL_I2C_Mem_Write(&hi2c1, LTC4015_DEVICE_ADDRESS_WRITE, 0x0D, I2C_MEMADD_SIZE_16BIT, dataBuffer0, 2, HAL_MAX_DELAY);

if (ret != HAL_OK)

{

Error_Handler();

}

 

 Am I doing anything wrong?

 

So my question is how to use the read & write functions for successful r/w operation.

 

Kindly explain me if you are available.

 

Device - stm32l0

 

 

Thanks & Regards

Satyabrata Senapati(Firmware Developer) 

Vasmed health sciences pvt ltd.

 

This topic has been closed for replies.
Best answer by TDK

The limited code that you showed looks okay to me.

Make sure the address is correct.

Prior to any I2C transfer, ensure HAL_I2C_IsDeviceReady returns HAL_OK. If it does not, you are not using the appropriate address, or something else is wrong.

1 reply

TDK
TDKBest answer
October 6, 2023

The limited code that you showed looks okay to me.

Make sure the address is correct.

Prior to any I2C transfer, ensure HAL_I2C_IsDeviceReady returns HAL_OK. If it does not, you are not using the appropriate address, or something else is wrong.

"If you feel a post has answered your question, please click ""Accept as Solution""."