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.

[参考译文] BQ27426:电量监测计 IC

Guru**** 1131400 points
Other Parts Discussed in Thread: BQ27426
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/power-management-group/power-management/f/power-management-forum/1332517/bq27426-fuel-gauge-ic

器件型号:BQ27426

大家好。 我正在尝试读取 BQ27426电量监测计 EVM 的器件类型。  

static int16_t BQ27426_i2cReadBytes(uint8_t reg, uint8_t *data, uint8_t len)
{
    ret_code_t err_code;
	m_xfer_done = false;
	err_code = nrf_drv_twi_tx(&twi0,BQ72426_I2C_ADDRESS, &reg, 1, true);
    APP_ERROR_CHECK(err_code);
   
	while(m_xfer_done == false){}
	if(NRF_SUCCESS != err_code)
	{
		return false;
	}
	m_xfer_done = false;
	err_code = nrf_drv_twi_rx(&twi0,BQ72426_I2C_ADDRESS, data, len );
    APP_ERROR_CHECK(err_code);
  
	while(m_xfer_done == false){}
	if(NRF_SUCCESS != err_code)
	{
		return false;
	}
    
	return true;
}

static int16_t BQ27426_i2cWriteBytes(uint8_t reg, uint8_t *data, uint8_t len)
{
    ret_code_t err_code  = nrf_drv_twi_tx(&twi0,BQ72426_I2C_ADDRESS ,data, len , false);
    APP_ERROR_CHECK(err_code); 
   
 
    while (m_xfer_done == false);
    if (err_code != NRF_SUCCESS)
    {
        NRF_LOG_INFO("Failed while calling twi tx, err_code = %d", err_code);
        return err_code;
    }
        nrf_delay_ms( BQ27426_DELAY );

    return NRF_SUCCESS;
}

uint16_t BQ27426_deviceType(void)
{  
    NRF_LOG_INFO("Reading device type...");
    uint16_t DeviceType = BQ27426_readControlWord(BQ27426_CONTROL_DEVICE_TYPE);
    NRF_LOG_INFO("Device type read :0x%x",DeviceType);
    return DeviceType;
}
static uint16_t BQ27426_readControlWord(uint16_t function) {

    uint8_t command[2] = {function & 0x00FF, function >> 8};
    uint8_t data[2] = {0, 0};
    NRF_LOG_INFO("Control word send: ");
    NRF_LOG_HEXDUMP_INFO(command,sizeof(command));
    BQ27426_i2cWriteBytes((uint8_t) 0, command,2);

    if (BQ27426_i2cReadBytes((uint8_t) 0, data, 2)) {
         NRF_LOG_INFO("Control word read: ");
          NRF_LOG_HEXDUMP_INFO(data,sizeof(data));
        return ((uint16_t) data[1] << 8) | data[0]; //Return 1
    }
    else{
        NRF_LOG_INFO("Failed to read Control word ");
        return false;
    }

   
}
我得到的器件类型是正确的0x426、但现在我得到的值是错误的、有时是0x8C 或0x9C。 是否有人可以帮助我理解问题所在。
我附上了供参考的代码。
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Nithin:  

    当您从电量监测计读取数据时、通信总线上是否还有其他东西? 这在我看来很奇怪,它是在一个点工作,但现在它不工作。

    此致、  

    Jonny.