BQ76930怎样通过IIC采用地址自动递增的方式读取各节电压信息?
我现在只能对单个寄存器地址进行读取,如果连续读就会出问题,下面是我的部分代码
unsigned char mxt_i2c_read_reg(u8 ADDR,u8 reg, u8 length, u8* buf)
{
mxt_i2c_start();
mxt_i2c_send_byte((ADDR<<1) | 0X00);
mxt_i2c_send_byte(reg);
mxt_i2c_stop();
mxt_i2c_start();
mxt_i2c_send_byte((ADDR<<1) | 0X01);
while(length)
{
if(length == 1)
{
*buf = mxt_i2c_read_byte(NOACK);
}
else
{
*buf++ = mxt_i2c_read_byte(ACK);
}
length--;
}
mxt_i2c_stop();
return 1;
}
void BQ76930_red_vcc(void)
{
u8 buf[40];
mxt_i2c_read_reg(BQ76930_ADDR,0x0c,1,&buf[0]);
mxt_i2c_read_reg(BQ76930_ADDR,0x0d,1,&buf[1]);
mxt_i2c_read_reg(BQ76930_ADDR,0x0e,1,&buf[2]);
mxt_i2c_read_reg(BQ76930_ADDR,0x0f,1,&buf[3]);
mxt_i2c_read_reg(BQ76930_ADDR,0x10,1,&buf[4]);
mxt_i2c_read_reg(BQ76930_ADDR,0x11,1,&buf[5]);
//mxt_i2c_read_reg(BQ76930_ADDR,0x12,1,&buf[6]);
//mxt_i2c_read_reg(BQ76930_ADDR,0x13,1,&buf[7]);
mxt_i2c_read_reg(BQ76930_ADDR,0x14,1,&buf[8]);
mxt_i2c_read_reg(BQ76930_ADDR,0x15,1,&buf[9]);
mxt_i2c_read_reg(BQ76930_ADDR,0x16,1,&buf[10]);
mxt_i2c_read_reg(BQ76930_ADDR,0x17,1,&buf[11]);
mxt_i2c_read_reg(BQ76930_ADDR,0x18,1,&buf[12]);
mxt_i2c_read_reg(BQ76930_ADDR,0x19,1,&buf[13]);
mxt_i2c_read_reg(BQ76930_ADDR,0x1a,1,&buf[14]);
mxt_i2c_read_reg(BQ76930_ADDR,0x1b,1,&buf[15]);
//mxt_i2c_read_reg(BQ76930_ADDR,0x1c,1,&buf[16]);
//mxt_i2c_read_reg(BQ76930_ADDR,0x1d,1,&buf[17]);
mxt_i2c_read_reg(BQ76930_ADDR,0x1e,1,&buf[18]);
mxt_i2c_read_reg(BQ76930_ADDR,0x1f,1,&buf[19]);
mxt_i2c_read_reg(BQ76930_ADDR,0x20,1,&buf[20]);
mxt_i2c_read_reg(BQ76930_ADDR,0x21,1,&buf[21]);
mxt_i2c_read_reg(BQ76930_ADDR,0x22,1,&buf[22]);
mxt_i2c_read_reg(BQ76930_ADDR,0x23,1,&buf[23]);
mxt_i2c_read_reg(BQ76930_ADDR,0x24,1,&buf[24]);
mxt_i2c_read_reg(BQ76930_ADDR,0x25,1,&buf[25]);
//mxt_i2c_read_reg(BQ76930_ADDR,0x26,1,&buf[26]);
//mxt_i2c_read_reg(BQ76930_ADDR,0x27,1,&buf[27]);
mxt_i2c_read_reg(BQ76930_ADDR,0x28,1,&buf[28]);
mxt_i2c_read_reg(BQ76930_ADDR,0x29,1,&buf[29]);
mxt_i2c_read_reg(BQ76930_ADDR,0x2a,1,&buf[30]);
mxt_i2c_read_reg(BQ76930_ADDR,0x2b,1,&buf[31]);
}
上面是对地址一个一个读的。
如果像下面这样就会出现问题
mxt_i2c_read_reg(BQ76930_ADDR,0x0c,30,&buf[0]);
所有的电压值都会是一个固定值。
难道这个只能一个一个去读吗?这样太耗时间了。
1 bq76930肯定是可以递增的读取的,
2. 检查以下read 函数底层实现, 看看是否是函数的问题。
还是没能解决这个问题,请问你那有BQ76930地址递增读取的时序图吗。
参考datashee 第29~30页