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.

BQ20Z95 Flash programming

Using the suggested VB functions for SaveDataFlashImageToFile() and  WriteDataFlashImageFromFile(), as described in document SLUA379B, the read function appears to work ok, however the write function corrupts the device and it stops responding over the SMBUS.  When I press the battery health button I just get a red flashing LED.

How can I fix this? I've included the code for the Write function below. 

Also, can you tell me what the difference is between SMBUS address &H16 and  &H17.  Also where can I find out more information about ROM access.

Thanks. 

Here's my write function:-

Sub Command2_Click()
Dim sFileName As String
Dim lerror As Long
Dim iFileNumber As Integer
Dim iNumberOfRows As Integer
Dim iRow As Integer
Dim iIndex As Integer
Dim yRowData(32) As Byte
Dim yRowDatax(32) As Byte
Dim yDataFlashImage(&H6C0) As Byte
Dim ERROR As Boolean
Dim Boards As Long
Dim boardName As String
Dim v As Variant
Dim iLen As Integer


sFileName = "c:\glyn.hex"
ERROR = OpenFirstFreeDevice(Boards, boardName)
'// READ THE FLASH IMAGE FROM THE FILE INTO A BYTE ARRAY
iFileNumber = FreeFile
Open sFileName For Binary Access Read As #iFileNumber
Get #iFileNumber, , yDataFlashImage
Close #iFileNumber
'// FOR CLARITY, WITHOUT USING CONSTANTS
iNumberOfRows = &H6C0 \ 32 '54 Rows
'// PUT DEVICE INTO ROM MODE
lerror = Form1.Bq80xRW1.WriteSMBusWord(&H0, &HF00, &H16)
DoDelay 0.01
'// ERASE DATA FLASH, ROWS ARE ERASED IN PAIRS
For iRow = 0 To iNumberOfRows - 1 Step 2
lerror = Form1.Bq80xRW1.WriteSMBusWord(&H11, iRow, &H17)
DoDelay 0.04
Next iRow

'// WRITE EACH ROW
For iRow = 0 To iNumberOfRows - 1
'// Set the row to program into the first element of the 33 byte array
yRowData(0) = iRow
'// Copy data from the full array to the row array
For iIndex = 0 To 31
yRowData(iIndex + 1) = yDataFlashImage((iRow * 32) + iIndex)
Next iIndex
'// Write the row. Length is 33 because the first byte is the row number
''lerror = WriteSMBusBlock(&H10, yRowData, 33)

lerror = Form1.Bq80xRW1.WriteSMBusBlock(&H10, yRowData, 33, &H17)

''v = yRowDatax
''lerror = Form1.Bq80xRW1.ReadSMBusBlock(&HC, v, iLen, &H16)
DoDelay 0.02
Next iRow
'// EXECUTE GAS GAUGE PROGRAM
lerror = WriteSMBusCommand(&H8, &H16)
MsgBox ("FLASH COMPLETE!")
End Sub

  • Glyn,

    I answered this via our e-mail scheme but apparently it didn't work. So, I copy it here. Sorry can't be more helpful.

    Glyn,
     
    1. The code looks good - you corrected the one known typo in there:
    yRowData(iIndex + 1) = yDataFlashImage((iRow * 32) = iIndex)
    Obviously, the second "=" sign should have been a "+"

    2. I have no idea why we defined yDataFlashImage as 0x700 bytes. Seems like it should have been 0x6c0 as you have done, but not completely sure.

    3. Don't know how you can fix it. Maybe you're definition of the various read and write functions is wrong (they are just examples), or perhaps your device is not going into ROM mode because it is not in full access mode. (see technical reference manual).

    4. The last bit of the device address is the read/write bit. A “0” for this bit denotes a write and a “1” for this bit denotes a read. So, address 0x16 is to write, and 0x17 is used to read.

    Regards,
    Doug
  • WriteSMBusCommand(&H8, &H16), should I use &H17 for this as I'm sending a Write command?

    Will the device stop responding when the Data Flash is blank?  if so, how do I recover from this?

    Thanks.

  • I now have two batteries I've lost comms with, the one that still has the cells attached gives error VB_UNKNOWN =  (6) when sending SMBUS commands, for the other one I removed the cells and re-connected and it now gives error  VB_SMB_NAC =  (772).

    Do you have any way to recover from this? If not, I need help to determine the cause of the problem to prevent me killing any more.

    Cheers, Glyn.

     

  • Glyn,

    Writes to SMBus only use 0x16. Reads use both 0x16 and 0x17. Please see attachment for additional information.

    A device with blank dataflash will probably not communicate.

    You should probably try to debug your comms development using an EVM and a bunch of spare ICs. There is a possible way to recover the IC's, but that cannot be disclosed on a public forum. I suggest you contact your local TI field apps engineer.

    Rgds,

    Doug

  • Glyn,

    if you read this post, answer please - did you get working write function that didnt corrupt bq?

    Best Regards,

    Eduard

  • Why is my ReadSMBusBlock function parameter different?
  • Why is my ReadSMBusBlock function parameter different?

    Why is my ReadSMBusBlock function parameter different?