Other Parts Discussed in Thread: BQ25798, TPS25751
Tool/software:
Hi Team:
I encountered a problem while using TPS25751 to read and write registers of BQ25798 using IIC. If I directly read the data from the register(0x01), the value is 00.But the result read by EE colleague on the computer is 0x0348, If I first write the data into the register and then read it,(Write 0x0346 to the 0x01 register), The data read back is also 0x3C46.But the data read by EE colleagues on the computer is still 0x0348.
Could you please help me check what could be causing it, such as code errors or hardware issues
Here is my reading and writing function and the returned log
[MSDK][TPS25751] read_reg: reg 08, value 04
[MSDK][TPS25751] CMD1 Status: 04 00 00 00 00
[MSDK][TPS25751] Read Data from BQ25798: 40 03 01 02 00 00 00 00
#define TPS25751_REG_CMD1 0x08 #define TPS25751_REG_DATA1 0x09 static int tps25751_read_bq25798_iindpm(const msdk_device_t *dev, uint8_t *data_out) { int ret = MSDK_STATUS__ERROR; // Step 1: Write DATA1 (0x09), with data to set up TPS25751 to read from BQ25798 uint8_t setup_data[4]; setup_data[0] = 0x03; // length = 3 bytes setup_data[1] = 0x6B; // BQ25798 I2C slave address setup_data[2] = 0x01; // target register in BQ25798 setup_data[3] = 0x02; // read 2 bytes ret = write_reg(dev, TPS25751_REG_DATA1, setup_data, sizeof(setup_data)); if (ret != MSDK_STATUS__OK) { MSDK_LOG_ERR("Failed to write TPS25751 DATA1"); return ret; } // Step 2: Write CMD1 (0x08) with 'I2Cr' command uint8_t i2cr_cmd[5] = { 0x04, 'I', '2', 'C', 'r' }; ret = write_reg(dev, TPS25751_REG_CMD1 , i2cr_cmd, sizeof(i2cr_cmd)); if (ret != MSDK_STATUS__OK) { MSDK_LOG_ERR("Failed to write TPS25751 CMD1 for I2Cr"); return ret; } // Step 3: Read CMD1 back to confirm command executed (should return 0x00 0x00 0x00 0x00) uint8_t cmd_status[5] = {0}; ret = read_reg(dev, TPS25751_REG_CMD1, cmd_status, sizeof(cmd_status)); if (ret != MSDK_STATUS__OK) { MSDK_LOG_ERR("Failed to read TPS25751 CMD1 status"); return ret; } MSDK_LOG_DBG("CMD1 Status: %02X %02X %02X %02X %02X", cmd_status[0], cmd_status[1], cmd_status[2], cmd_status[3],cmd_status[4]); // Step 4: Read back the 2 bytes result from DATA1 (0x09) ret = read_reg(dev, TPS25751_REG_DATA1, data_out, 4); if (ret != MSDK_STATUS__OK) { MSDK_LOG_ERR("Failed to read response from TPS25750 DATA1"); return ret; } MSDK_LOG_DBG("Read Data from BQ25798: %02X %02X %02X %02X", data_out[0], data_out[1],data_out[2],data_out[3]); return MSDK_STATUS__OK; } static int tps25751_write_bq25798_iindpm(const msdk_device_t *dev) { int ret = MSDK_STATUS__ERROR; // Step 1: Write to TPS25751's DATA1 register (0x09) // Data: 05 6b 03 06 00 C8 // -> Length = 5 // -> Slave address = 0x6B // -> Write operation (0x03) // -> Register = 0x01 // -> Data = 0x0346 uint8_t data1_setup[] = { 0x05, 0x6B, 0x03, 0x06, 0x03, 0x46 }; ret = write_reg(dev, TPS25751_REG_DATA1, data1_setup, sizeof(data1_setup)); if (ret != MSDK_STATUS__OK) { MSDK_LOG_ERR("Failed to write TPS25751 DATA1"); return ret; } // Optional: Verify write to DATA1 uint8_t data1_readback[6] = {0}; ret = read_reg(dev, TPS25751_REG_DATA1, data1_readback, sizeof(data1_readback)); if (ret != MSDK_STATUS__OK) { MSDK_LOG_ERR("Failed to read back TPS25750 DATA1"); return ret; } MSDK_LOG_DBG("DATA1 Readback: %02X %02X %02X %02X %02X %02X", data1_readback[0], data1_readback[1], data1_readback[2], data1_readback[3], data1_readback[4], data1_readback[5]); // Step 2: Write 'I2Cw' to CMD1 register (0x08) uint8_t i2cw_cmd[] = { 0x04, 'I', '2', 'C', 'w' }; ret = write_reg(dev, TPS25751_REG_CMD1, i2cw_cmd, sizeof(i2cw_cmd)); if (ret != MSDK_STATUS__OK) { MSDK_LOG_ERR("Failed to send I2Cw command to CMD1"); return ret; } // Step 3: Read back CMD1 status uint8_t cmd_status[5] = {0}; ret = read_reg(dev, TPS25751_CMD1_REG, cmd_status, sizeof(cmd_status)); if (ret != MSDK_STATUS__OK) { MSDK_LOG_ERR("Failed to read CMD1 status\n"); return ret; } MSDK_LOG_DBG("CMD1 Status: %02X %02X %02X %02X %02X", cmd_status[0], cmd_status[1], cmd_status[2], cmd_status[3],cmd_status[4]); return MSDK_STATUS__OK; }

Best Regards!
Iris