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.

bq27421通讯问题



在bq27421的配置中,我按照技术文档上的例子顺序去写Data Memory parameter,按照顺序执行的时候,在写0x61寄存器值00的时候,i2c就不再返回了,i2c直接读取当前电量没有问题。代码顺序如下,到61就过不去了

i2ctxbuf[0]=0;
    I2C_BufWriteT(0xAA,0x00, i2ctxbuf, 1);   //0xaa 芯片地址,0x00 寄存器地址
  i2ctxbuf[0]=0x80;
  I2C_BufWriteT(0xAA,0x00, i2ctxbuf, 1);   //0xaa 芯片地址,0x00 寄存器地址
  I2C_BufWriteT(0xAA,0x00, i2ctxbuf, 2);
  i2ctxbuf[0]=0x13;
  i2ctxbuf[1]=0x0;
  I2C_BufWriteT(0xAA,0x00, i2ctxbuf, 2);
  while((EEP.ReadBuf[0]&0x10)!=0x10)
  {
    I2C_BufReadT(0xAA,0x06 , 1);
    OSTimeDly(500);
  }
 // OSTimeDly(1000);
  i2ctxbuf[0]=0;
  I2C_BufWriteT(0xAA,0x61, i2ctxbuf, 1);
  i2ctxbuf[0]=0x52;
  I2C_BufWriteT(0xAA,0x3e, i2ctxbuf, 1);

  • 在每个i2C读取指令后面可以增加2ms的延迟试一下,

  • 增加延迟没有效果,我发现在每次读取操作后,再执行写操作就会无应答,而我把配置芯片的步骤取消,直接在任务里读取电量没有问题。应该读取函数没有问题,在读取和写函数中都有信号量等待,在i2c操作完成后才会往后执行。

    这是任务中的代码

    //Battery_Init();
      while(1)
      {
       
        I2C_BufReadT(0xAA,0x0c ,4);  //读取0xc 0xd  0xe 0xf寄存器
        RemainCapacity=(EEP.ReadBuf[1])<<8|EEP.ReadBuf[0];
        FullCapacity=(EEP.ReadBuf[3])<<8|EEP.ReadBuf[2];
        OSTimeDly(1000);
      }

    我在debug的时候单步运行Battery_Init,屏蔽以下代码的时候,可以继续往下执行,在读到OLD_Csum后,再执行下一步时就无应答了

    i2ctxbuf[0]=0x13;
      i2ctxbuf[1]=0x0;
      I2C_BufWriteT(0xAA,0x00, i2ctxbuf, 2);
      OSTimeDly(2);
    //  while((EEP.ReadBuf[0]&0x10)!=0x10)
    //  {
    //    I2C_BufReadT(0xAA,0x06 , 1);
    //    OSTimeDly(500);
    //  }
      OSTimeDly(2000);
      i2ctxbuf[0]=0;
      I2C_BufWriteT(0xAA,0x61, i2ctxbuf, 1);
      OSTimeDly(2);
      i2ctxbuf[0]=0x52;
      I2C_BufWriteT(0xAA,0x3e, i2ctxbuf, 1); 
      i2ctxbuf[0]=0x0;
      I2C_BufWriteT(0xAA,0x3f, i2ctxbuf, 1);
      OSTimeDly(2);
      I2C_BufReadT(0xAA,0x60 , 1);

    //  OSTimeDly(2);
      OLD_Csum=EEP.ReadBuf[0];
      I2C_BufReadT(0xAA,0x4a , 1);