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