最近在一个项目中要调试一个颗粒:BQ27531,其芯片有一点特殊,是TI的电池管理方面的片子。

我在用CH341A调试时,发现无法正常的读取,后用示波器观察,发现BQ27531的ACK好像给的比较晚?又或者是其它原因,BQ27531的SCL会被拉低一段时间,大概有44us左右。

我在想,是不是BQ27531处于其它的状态,导致CH341A的ACK断言应该延后判断。

不知道CH341A是否可以等待的?



BOOL WINAPI BQ27531(
        ULONG iIndex,
        UCHAR CMD,
        PUCHAR InByte)
{
    UCHAR    mBuffer[mCH341_PACKET_LENGTH];
    ULONG    mLength, mInLen;
    ULONG   CH341_Status;

    mBuffer[0] = mCH341A_CMD_I2C_STREAM;    //command code
    mBuffer[1] = mCH341A_CMD_I2C_STM_STA;   //start bit
    mBuffer[2] = mCH341A_CMD_I2C_STM_OUT;    //the data we send, bit5~bit0 means the number of data which be sent out, 这个bit5~bit0设置好,发送死机,CH341A挂死一样的状态。
    mBuffer[3] = 0xAA;             // write address, BQ27531的设备地址。
    mBuffer[4] = mCH341A_CMD_I2C_STM_END;   //pkt end.
    mLength = 5;
    mInLen = 0;
    if(USBIO_WriteRead(iIndex, mLength, mBuffer, mCH341A_CMD_I2C_STM_MAX, 1, &mInLen, mBuffer))
    {
        if(mInLen && ( mBuffer[ mInLen - 1] & 0x80 )==0)
        {
            mBuffer[0] = mCH341A_CMD_I2C_STREAM;    //command code
            mBuffer[1] = mCH341A_CMD_I2C_STM_OUT; //发送一个从设备的内部地址,设为0x00
            mBuffer[2] = CMD;
            mBuffer[3] = mCH341A_CMD_I2C_STM_END;
            mLength = 4;
            mInLen = 0;
            if(USBIO_WriteRead(iIndex, mLength, mBuffer, mCH341A_CMD_I2C_STM_MAX, 1, &mInLen, mBuffer)) //执行完上一句话后,奇怪的是CH341A不再做应答检测?这里我不太理解,我看到SCL只发送了8bit的时钟,不太理解。
            {
                if(mInLen && ( mBuffer[ mInLen - 1] & 0x80 )==0)
                    std::cout << "ACK is okay ......\n";
//                while(1)
//                {
//                    USBIO_GetStatus(iIndex, &CH341_Status);
//                    if( CH341_Status == 0x80eFFF)break;
//                    else std::cout << "Status: " << std::hex << CH341_Status << std::endl;
//                }

            }
        }
    }

    return (TRUE);