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.

Missing definition ReadSMBusByteArray and WriteSMBUsByteArray and WriteSMBuSCommand

Hello everyone,

i would like to read and write data flash to make golden pack.


i am using a raspberry pi to do that, i translate the VB code (slu379E) in C code but i have a probleme with 2 SMBus function.

WriteSMBusByteArray

WriteSMBusCommand


Where i can found this c code or vb code?

Thanks in advance for your help

  • Hi,

    so i translate vb SaveDataFlashImageToFile in c code, the SMBus function used is correct or not ? thanks in advance for your help

    Function SaveDataFlashImageToFile(sFileName As String) As Long
    Dim iNumberOfRows As Integer
    Dim lError As Long
    Dim yRowData(32) As Byte
    Dim yDataFlashImage(&H700) As Byte
    Dim iRow As Integer
    Dim iIndex As Integer
    Dim iLen As Integer
    Dim iFileNumber As Integer
    '// FOR CLARITY, WITHOUT USING CONSTANTS
    '// 0x700 is the data flash size.
    0x700 \ 32 = 56 rows
    iNumberOfRows = &H700 \ 32
    '// PUT DEVICE INTO ROM MODE
    lError = WriteSMBusInteger(&H0, &HF00)
    DoDelay 0.01
    '// READ THE DATA FLASH, ROW BY ROW
    For iRow = 0 To iNumberOfRows - 1
    '// Set the address for the row. &H9 (0x09) is the ROM mode command.
    '// 0x200 is the row number where data flash starts.
    '// Multiplication by 32 gives us the actual physical address where each row starts
    lError = WriteSMBusInteger(&H9, (&H200 + iRow) * 32)
    '// Read the row. &HC (0x0c) is the ROM mode command.
    lError = ReadSMBusByteArray(&HC, yRowData, iLen)
    '//Copy this row into its place in a big byte array
    For iIndex = 0 To 32 - 1
    yDataFlashImage((iRow * 32) + iIndex) = yRowData(iIndex)
    Next iIndex
    Next iRow
    '// WRITE DATA FLASH IMAGE TO FILE
    iFileNumber = FreeFile
    Open sFileName For Binary Access Write As #iFileNumber
    Put #iFileNumber, , yDataFlashImage
    Close #iFileNumber
    '// EXECUTE GAS GAUGE PROGRAM
    lError = WriteSMBusCommand(&H8)
    End Function

    VB to C code with SMBus Functions, what you think about that it is right or absoluty wrong ?

    #include <stdlib.h>
    #include <stdio.h>
    
    long lError;
    int iFileNumber, iNumberOfRows, iRow, iIndex;
    bytes[] yRowData = new byte[32];
    bytes[] yDataFlashImage = new byte[1792]; // 0x700
    
    #define ADRESSE_SLAVE 0xXX
    
    FILE* fichier = NULL;
    
    // 0x700 taille diviser par 32
    iNumberOfRows = 56;
    // mettre le bq20z655 en mode ROM
    lError = i2c_smbus_write_word_data(0x00,0x0F00);
    // pause à vérifier
    sleep(10);
    // lecture de la flash
    
    for(iRow=0;iRow<iNumberOfRows;iRow+1)
    {
    	// 0x09 rom mod command
    	// 0x200 strat row flash
    	// x32 the next row 
    	lError = i2c_smbus_write_word_data(ADRESSE_SLAVE, 0x09, (0x200+iRow)*32);
    	
    	// 0x0c rom mod command
    	lError = i2c_smbus_read_i2c_block_data(ADRESSE_SLAVE, 0x0C, yRowData, iLen);
    	
    	for(iIndex=0; iIndex<32; iIndex+1)
    	{
    	yDataFlashImage((iRow*32)+iIndex) = yRowData(iIndex);
    	}	
    }
    
    fichier = fopen("data_flash.txt", "w");
    
    if(fichier != NULL)
    {
    	fputs(yDataFlashImage,fichier);
    	fclose(ficher);
    }

    lError = i2c_smbus_write_word_data(ADRESSE_SLAVE,0x00,0x0008);

  • I use a Raspberry PI to read and wirte the bq20z655 but the target device on SMBus is 0x48 and 0x0b but not 0x16.


    What's happen, can you explain why i can't see the 0x16 address ?

    Thank's you in advance