Search code examples
cmicrocontrolleri2c

MAX77651 Can't read register with i2c


I am trying to test the i2c communication of the MAX77651 chip before programming it.

So here is my setup to do so:

I have an UMFT4222ev connected to my Linux laptop by USB. This chip has his SCL and SDA linked to the SDA and SCL of my MAX77651 thanks to the Evaluation Kit for the MAX77651. My MAX77651evkit is powered with 3,7V on the Vbatt pin.

I also installed the mraa librarie from git hub and the libft4222. I know mraa is well installed because i tried it with and example.

I was told that the mraa library takes in charge the setup of the FT4222 so i only used mraa functions to make my program.

I searched on the website of Maxim integrated the i2c slave address and one register where i could read data and check if everyting is working. I then read the i2c protocol of communication to read a single register which is available here : https://datasheets.maximintegrated.com/en/ds/MAX77650-MAX77651.pdf at the page 78.

With all those informations I tried to make my "test program". I solved the compiling errors but when I execute the program I can't get what is in the register which should be 0xFF.

Here is my program:

#include "stdio.h"
#include "syslog.h"
#include "string.h"
#include "unistd.h"
#include "mraa/i2c.h"
#include "mraa.h"

#define I2C_ADDR 0x48

int
main(int argc, char *argv[])
{
uint8_t *message;
*message=0XAC;
int i,j,k;
char reg_a_lire = 0x06; 

mraa_init();    
mraa_i2c_context i2c;


i2c = mraa_i2c_init(0);
mraa_i2c_frequency(i2c,MRAA_I2C_FAST);


mraa_i2c_address(i2c, I2C_ADDR);

mraa_i2c_write_byte(i2c,0x90);


mraa_i2c_read(i2c, message,1);


mraa_i2c_write_byte(i2c,reg_a_lire);


mraa_init();


mraa_i2c_write_byte(i2c,0x91);

mraa_i2c_read(i2c, message,1);

mraa_i2c_read(i2c, message,1);

printf("%02X \n", *message);
mraa_i2c_stop(i2c);

return 0;
}

Here is the actual output :

alex@cyclonit-laptop ~/Test_alex/tests $ ./a.out
AC 

And i would like to get FF instead of AC.

I think my error could come from something i missed to initialize the FT4222 or from the MAX77651 which I maybe did nt power up correctly and its not sufficient to put 3,7V on Vbatt. But maybe this is a problem with my program because i don't know much about uint8_t and I made something wrong.

I am hoping someone has experience with FT4222 and/or MAX77651 and can help me.


Solution

  • I managed to read I2C registers of MAX77651.

    First looking at the hardware part I had to make sure that VIO had the right voltage like @FRob said in hid comment.

    Then for the software, I stopped using the mraa library because i could'nt control everything. I used the FT4222 library which allowed me to open and initiate the FT4222 device. I took some part of the I2C example in this library for the initialization of the device. Then I noticed that I had to first use the FT4222's write function to send the register i wanted to read , then simply use the read function to get my result. Those are the two steps required.

    I won't post the whole program i made as it is mainly taken from the I2C example for initialization but here is the part I added to read my register 0X06 which is supposed to contain 0xFF:

    uint8 resultat=0x11;
    uint8 *p_resultat=&resultat;
    int chiffre;
    slaveAddr
    uint16 bytesToWrite2 = 1;
    uint16 bytesWritten2=1;
    uint8 valeur= 0x06;                              // REGISTER TO READ
    uint8 *p_valeur=&valeur;    
    
    
    FT4222_I2CMaster_Write(ftHandle,slaveAddr,
    p_valeur,bytesToWrite2,&bytesWritten);  //INDICATES WHICH REGISTER TO 
                                            //                       READ
    
    chiffre = FT4222_I2CMaster_Read(ftHandle, 
    slaveAddr,p_resultat,1, &bytesRead);     // READ REGISTER
    
    printf("The content of the register %02X is : %02X \n " , 
    valeur,resultat);    // DISPLAY RESULT
    
    printf("reading success if : %d = 0 \n " , chiffre);                 
    // READING SUCCESS ?
    

    With this code and the initialization i get the following result :

    alex@cyclonit-laptop ~/Downloads/libft4222-1.2.1.4/examples $ ./a.out
    
    Device 0 is interface A of mode-0 FT4222H:
    0x0403601c    FT4222 A
    Chip version: 42220200, LibFT4222 version: 01020104
    The content of the register 06 is : FF 
    reading success if : 0 = 0 
    Skipping interface B of mode-0 FT4222H.
    

    If someone has the same problem you are free to ask me your question by answering this post.I am very thankful to the people here who helped me!