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.

BQ40Z50: bq40z50 VB6.0 SMBus Block read & write issue

Part Number: BQ40Z50
Other Parts Discussed in Thread: BQSTUDIO, EV2400

Dear RD or supporter:

    Based on EV2300 VB customer kit , i want to develop an auto barcode comparing tool(compare Pack's barcode and manufacture info in Dataflash)  Based on the bq40z50 RTM, write SMBus Block address 0x44, data 0x70 00, then read SMBus block 0x23, the manufacture info(Barcode in Dataflash), Unfortunately, i can not found SMBusBlock read&write operation program in EV2300 VB customer kit codes, i am trying to write and read SMBus Block for many times, but i am failed. Could you please give me some advice, thank you.

I'm looking forward to hearing from you

Best regards

Mike Lee

  • Hello Mike,

    The EV2300 is an old device that can no longer be supported fully. What customer codes are you referring to?

    You can use an SMBus or I2C API to communicate with the gauge and use the TRM as a guide for the commands to send.

    Sincerely,

    Wyatt Keller

  • Hello Wyatt,

       Thanks for your prompt response.

    I am not familiar with SMBus API to communicate with the gauge, could you please give me an example regarding to SMBus block and SMBus word read/write.

    I'd like to read manufacturer info, but i not good at reading code of SMBusBlock, the codes of Visual Basic 6 are as following, could you please help to fix the codes of ReadSMBusBlock ,thanks a lot.

    Main sub codes

    ModUSB codes

    Best regards

    Mike Lee

  • Hello Wyatt,

       Because the pic can not be showed correctly, update the codes

    Main Sub

    If (Len(Text12.Text) <= 2) Then ' SMBusword write Manufacturer Acces 0x00,data=0070
    WordHexToHex Text12.Text
    If (Len(Text20.Text) <= 4) Then
    DataH5 = WordHexToHex(Text20.Text) \ 256
    DataL5 = WordHexToHex(Text20.Text) Mod 256
    lerror5 = WriteSMBusWord(ByteHexToHex(Text23.Text), DataH5, DataL5)
    End If

    End If

    Call time_delay(2)

    Res = 20
    If (Len(Text21.Text) <= 2) Then 'SMBusBlock read Manufacturer 0x23
    lerror7 = ReadSMBusBlock(ByteHexToHex(Text21.Text), Res)
    End If

    str = InputBox("请输入字符串")
    For i = 1 To Len(str)
    ascstr = ascstr & CStr(Asc(Mid(str, i, 2)))
    Next i

    Text19.Text = ascstr

    ModUSB

    Public Function ReadSMBusBlock(ByVal ySubCommand As Byte, sResponse As String) As Long
    Dim lerror As Long
    Dim Data(128) As Byte
    Dim nLen As Integer
    Dim SubCmd As Integer
    SubCmd = ySubCommand
    'To call ReadSMBusBlock() we need a pointer to variant containing array of bytes
    'So assign an array of bytes to variant v and use v as argument to the call
    Dim v As Variant
    v = Data
    sResponse = ""
    lerror = Form1.Bq80xRW1.ReadSMBusBlock(SubCmd, v, nLen, &H17)
    If lerror = 0 Then 'Stick return data into a string
    Dim X As Integer
    For X = 0 To nLen - 1
    'sResponse = sResponse & Chr(v(X)) This will display actual string for mfg name
    Dim tmpStr As String
    tmpStr = Hex$(v(X))
    If Len(tmpStr) < 2 Then
    tmpStr = "0" & tmpStr
    End If
    sResponse = sResponse & tmpStr
    Next X
    End If

    ' ReportCommErrors lError
    ReadSMBusBlock = lerror
    End Function

    Best regards

    Mike Lee

  • Hello Mike,

    I won't be able to help debug your code, we have some app notes regarding gauge communication that may be helpful for you: www.ti.com/.../slua801.pdf

    I would recommend using the EV2400 and logic analyzer to debug what commands you are sending with your MCU compared to the EV2400 and bqStudio.

    Sincerely,

    Wyatt Keller