cancel
Showing results for 
Search instead for 
Did you mean: 

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

mrtaotao789
Associate II
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

__/|\__

11 REPLIES 11
Posted on March 01, 2017 at 11:13

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

JW

Posted on March 01, 2017 at 18:12

0690X00000603hbQAA.jpg
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

Posted on March 01, 2017 at 21:11

KIC,

that's no start/stop. Although the marks are barely visible, the yellow line is clearly permanently at zero. It means, the I2C machine attempts to do a START but as one of SDA/SCL is permanently low, it can't do that and gives up. I bet there's some error in the registers; I don't Cube so I don't know how to detect that in that realm.

SIRI.PISIT

find out why is the signal corresponding to the yellow line at zero, first. Even without any attempt to do I2C, after pins initialization, both pins shall be at one. You init them as open-drain, AF mode, properly chosen AF; and you do have external pullups?

JW

Posted on March 01, 2017 at 22:18

Power off on your eeprom to get back to I2C idle mode each time you try debug the I2C.

mrtaotao789
Associate II
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
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
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
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 

_/\_