This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

BQ25798EVM: Is the charger (BQ25798) using Big-Endian or Little-Endian

Part Number: BQ25798EVM
Other Parts Discussed in Thread: BQ25798

Tool/software:

Hi team,

I am currently facing two questions and would like to consult with you
(1) Is the charger (BQ25798) using Big Endian or Little Endian, not clearly defined on the datasheet
(2) At present, we want to use the chaeger as an independent IC, so can't we control the charger through PD using 4CC instructions?

(3)Previously, we were able to successfully control the charger to enter shipping mode using PD and 4CC commands. However, now that we have separated the charge and directly controlled it using MCU, we cannot enter shipping mode. Could you please help us identify which step the problem lies in? Attached is the code

static uint16_t read_reg(const msdk_device_t *dev, bq25798_reg_t reg, uint8_t reg_width)
{
    int ret;
    uint8_t data[2] = {0};
    bq25798_cfg_t *dev_config = (bq25798_cfg_t *) dev->config;

    ret = msdk_i2c_read_reg(dev_config->i2c_dev, dev_config->i2c_addr, reg, data, reg_width);
    if (ret != MSDK_STATUS__OK) {
        MSDK_LOG_ERR("read_reg failed addr: 0x%x", reg);
    }

    if (reg_width == 1) {
        return data[0];
    }   
else {
        return (uint16_t)(data[0] << 8 | data[1]);
    }
}

static int write_reg(const msdk_device_t *dev, bq25798_reg_t reg, uint16_t value, uint8_t reg_width)
{
    int ret = MSDK_STATUS__ERROR;
    uint8_t data[2];
    bq25798_cfg_t *dev_config = (bq25798_cfg_t *) dev->config;

    if (reg_width == 1) {
        data[0] = value & 0xFF;
    } 
    else {
        data[0] = value & 0xFF;
        data[1] = (value >> 8) & 0xFF;
    }

    ret = msdk_i2c_write_reg(dev_config->i2c_dev, dev_config->i2c_addr, reg, data, reg_width);
    if (ret != MSDK_STATUS__OK) {
        MSDK_LOG_ERR("write_reg failed addr: 0x%x", reg);
    }

    return ret;
}

/**
* @brief Enable/Disable otg out function
* @param[in] true: enable, false: disable
* @return true: Success, false: Failed
*/
static int enable_otg_out(const msdk_device_t *dev, bool en)
{
    uint16_t data;
    int ret = MSDK_STATUS__ERROR;
    bool curr_en;

    data = read_reg(dev, BQ25798_REG_CHG_CONTROL_3, 1);

    curr_en = (bool)get_bit_field(data,
                                BITMASK_CHG_CONTROL_3_EN_OTG,
                                SHIFT_CHG_CONTROL_3_EN_OTG);

    if (en == curr_en) {
        return true;
    }

    data = set_bit_field(data,
                        BITMASK_CHG_CONTROL_3_EN_OTG,
                        SHIFT_CHG_CONTROL_3_EN_OTG,
                        en);

    ret = write_reg(dev, BQ25798_REG_CHG_CONTROL_3, data, 1);

    return ret;
}
/*Call after PD download patch is successful*/
int bq25798_enable_ship_fet(const msdk_device_t *dev)
{
    uint8_t reg_val = 0;
	
    reg_val = read_reg(dev, 0x14,1);

    reg_val |= (1 << 7); // Set bit7 to 1, keeping all other bits unchanged
	
	ret = write_reg(dev, 0x14, &reg_val, 1);
	
	if (ret != MSDK_STATUS__OK) {
        MSDK_LOG_ERR("Failed to write REG14.");
        return ret;
    }

    return MSDK_STATUS__OK;
	
}
/*Call during shutdown*/
int bq25798_enter_shipping_mode(const msdk_device_t *dev)
{
    uint8_t reg_val = 0;
	reg_val = 0x80;
	
	write_reg(dev, 0x4, &reg_val, 1);
	
    reg_val = read_reg(dev, 0x11,1);
    // Modify SDRV_CTRL [1:0] bits to 10
    reg_val = (reg_val & ~0x07) | 0x05;

    ret = write_reg(dev, 0x11, &reg_val, 1);
    if (ret != MSDK_STATUS__OK) {
        MSDK_LOG_ERR("Failed to write REG11 to enter shipping mode.");
        return ret;
    }

    return MSDK_STATUS__OK;
}

Best Regards!

Iris