Skip to main content
mrtaotao789
Associate II
March 1, 2017
Question

STM32F103C8, I2C1 with EEPROM_AT24C16C, it does not work T_T!

  • March 1, 2017
  • 5 replies
  • 2869 views
Posted on March 01, 2017 at 08:34

Initial Gencode : CubeMX : V4.19

IDE : KEIL       : V5.23.0.0 

HW : EEPROM : AT24C16C

minimum board STM32F103C8T6

HSE 72MHz

i pullup SDA, SCL with R 4k7 (PB7 & PB6)

Mode speed 100kHz

// this is my code.. //

my_i2c_status[0] = HAL_I2C_IsDeviceReady( &hi2c1,(uint16_t)0xA1,(uint16_t)10,3000);

my_dat[0] = 10;

my_dat[1] = 11;

my_dat[2] = 12;

my_get[0] = 0;

my_get[1] = 0;

my_get[2] = 0;

HAL_I2C_Mem_Write( &hi2c1,(uint16_t)0x00A0, (uint16_t)0, (uint16_t)8, my_dat, 3, 3000);

HAL_I2C_Mem_Read( &hi2c1,(uint16_t)0x00A1, (uint16_t)0, (uint16_t)8, my_get, 3, 3000);

my_get[0] =0 ,

my_get[1] =0 ,

my_get[2] =0 ,

It not change

T_T!

what is mistake in my code.

thank you very much

__/|\__

    This topic has been closed for replies.

    5 replies

    waclawek.jan
    Super User
    March 1, 2017
    Posted on March 01, 2017 at 11:13

    What re the SDA/SCL waveforms when looking by an oscilloscope or logic analyzer?

    JW

    mrtaotao789
    Associate II
    March 1, 2017
    Posted on March 01, 2017 at 18:12

    0690X00000603hbQAA.jpg
    S.Ma
    Principal
    March 1, 2017
    Posted on March 01, 2017 at 18:37

    Try replacing

    HAL_I2C_Mem_Write( &hi2c1,(uint16_t)0x00A0, (uint16_t)0, (uint16_t)8, my_dat, 3, 3000);

    HAL_I2C_Mem_Read( &hi2c1,(uint16_t)0x00A1, (uint16_t)0, (uint16_t)8, my_get, 3, 3000);

    by

    HAL_I2C_Mem_Write( &hi2c1, 0x00A0, 0x0000, 8, my_dat, 3, 3000);

    HAL_Delay(10);

    HAL_I2C_Mem_Write( &hi2c1, 0x00A0, 0x0000, 2, my_dat, 0, 3000);

    HAL_I2C_Mem_Read( &hi2c1, 0x00A1, 0x0000, 2, my_get, 3, 3000);

    It a bit overblown, let's see if you get more than a Start/Stop

    mrtaotao789
    Associate II
    March 2, 2017
    Posted on March 02, 2017 at 04:38

                                                     <<>> This is latest coding  <<>>

    // I2C_HandleTypeDef                                      *hi2c,      DevAddress,        Trials,      Timeout

    my_i2c_status = HAL_I2C_IsDeviceReady( &hi2c1,    (uint16_t)0xA1, (uint16_t)10,   3000);

    //-------------------------------------------------------------------------------------------------------------------//

    /** my_i2c_status = 0x01.. or  HAL_ERROR   what happen..  T_T  **/

    //-------------------------------------------------------------------------------------------------------------------//

    my_dat = 1;      

    my_get = 0xFF;

    //I2C_HandleTypeDef     *hi2c,     DevAddress,          MemAddress,    MemAddSize,     *pData,       Size,  Timeout

    HAL_I2C_Mem_Write(   &hi2c1,  (uint16_t)0x00A0,   (uint16_t)0,        (uint16_t)8,           &my_dat,   1,       3000);

    HAL_I2C_Mem_Read(   &hi2c1,  (uint16_t)0x00A1,   (uint16_t)0,        (uint16_t)8,           &my_get,   1,       3000);

    //------------------------------------------------------------------------------------------------------------------------------------------------//

    my_get = 0xFF 

    what is mistake ?

    Thank you very much.0690X00000603bjQAA.jpg

    mrtaotao789
    Associate II
    March 2, 2017
    Posted on March 02, 2017 at 05:05

    my_dat = 1;

    my_get = 0xFF;

    //I2C_HandleTypeDef *hi2c, DevAddress, MemAddress, MemAddSize, *pData, Size, Timeout

    HAL_I2C_Mem_Write( &hi2c1, (uint16_t)0x00A0, (uint16_t)0, (uint16_t)8, &my_dat, 1, 3000);

    HAL_I2C_Mem_Read( &hi2c1, (uint16_t)0x00A1, (uint16_t)0, (uint16_t)8, &my_get, 1, 3000);

    What is mistake..??

    T T

    0690X00000603edQAA.jpg
    S.Ma
    Principal
    March 2, 2017
    Posted on March 02, 2017 at 10:22

    The chip slave address A0 is NACK => either the slave address is wrong, or bad soldering, or SDA/SCL connection is wrong. If possible, probe the EEPROM package pins and make sure it has supply and ground ok.

    mrtaotao789
    Associate II
    March 2, 2017
    Posted on March 02, 2017 at 11:58

    I think my soldering is ok, i checked  :)

    and this is datasheet of EEPROM

    but now, i don not understand

    what is mistake ??

    T_T!

    0690X00000606SjQAI.png

    and latest, this is code :

    // I2C_HandleTypeDef *hi2c, DevAddress, Trials, Timeout

    //my_i2c_status = HAL_I2C_IsDeviceReady( &hi2c1, (uint16_t)0xA1, (uint16_t)10, 3000);

    my_dat = 0x55;

    my_get = 0x00;

    //I2C_HandleTypeDef *hi2c, DevAddress, MemAddress, MemAddSize, *pData, Size, Timeout

    HAL_I2C_Mem_Write( &hi2c1, (uint16_t)0x00A0, (uint16_t)0, (uint16_t)1, &my_dat, 1, 3000);

    HAL_I2C_Mem_Read( &hi2c1, (uint16_t)0x00A1, (uint16_t)0, (uint16_t)1, &my_get, 2, 3000);

    and this is a capture from Saleae analyzer:

    0690X00000606T3QAI.png

    in last lie of coding.. i set addr = 0xA1

    but it as 0xA0 on Scope.  O_o!

    i do not understand.

    Thank you very much 

    _/\_

    Nicolas Felipe
    Associate II
    March 5, 2017
    Posted on March 05, 2017 at 03:47

    could u please share how u used to work with the eeprom? i have not ur level of knowledge and have been struggling for like 1 week now trying to read and write from an AT24C02 , im using too an 

    STM32F103C8T6,

    i have tested this and many other kind of codes but nothing :S 

    xBuffer[0] = 'M';

    HAL_I2C_Mem_Write(&hi2c1, 0x57, 0x0007, 2, xBuffer, 1, 5);

    HAL_Delay(10);

    xBuffer[0] = 0x00;

    HAL_I2C_Mem_Write(&hi2c1, 0x57, 0x0007, 2, xBuffer, 0, 5);

    HAL_I2C_Mem_Read(&hi2c1, 0x57, 0x0007, 2, xBuffer, 1, 5);*/

    HAL_Delay(2000);

    mrtaotao789
    Associate II
    March 4, 2017
    Posted on March 04, 2017 at 06:55

    Now, i can solve i2c,

    Lib from HAL.. 

    HAL_I2C_Mem_Read() :

    Algorythm of HAL_Lib is not mathing with EEPROM, so it can not use

    i coding easy functions for solve this problem and oscillope by Saleae Logic Analyzer,

    i follow timing diagram of RM0008 of STM and data sheet of EEPROM

    Now it work..

    but HAL_I2C_Mem_Write() : it is correct, it can use

    thank you every body :)

    ___/\___0690X00000606IMQAY.png0690X00000606OiQAI.png