最近在一個項目中要調試一個顆粒:BQ27531,其芯片有一點特殊,是TI的電池管理方面的片子。
我在用CH341A調試時,發(fā)現無法正常的讀取,后用示波器觀察,發(fā)現BQ27531的ACK好像給的比較晚?又或者是其它原因,BQ27531的SCL會被拉低一段時間,大概有44us左右。
我在想,是不是BQ27531處于其它的狀態(tài),導致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設置好,發(fā)送死機,CH341A掛死一樣的狀態(tài)。
??? 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; //發(fā)送一個從設備的內部地址,設為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)) //執(zhí)行完上一句話后,奇怪的是CH341A不再做應答檢測?這里我不太理解,我看到SCL只發(fā)送了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);