cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_I2C_Mem_Read reads only correct if the parameter is wrong

Osto
Senior
Posted on September 24, 2014 at 13:18

Hi,

I have a STMCube generated project wirh I2C memory 24LC512 with following problem. The line:

Status = HAL_I2C_Mem_Read(&hi2c1, IIC_ADDRESS+1, 0, I2C_MEMADD_SIZE_8BIT, pNVRawData, NVRawDataLen, 1000);

is correct feeded with parameter but reads only 0xff as data.

The line:Status = HAL_I2C_Mem_Read(&hi2c1, IIC_ADDRESS+1, 0, I2C_MEMADD_SIZE_8BIT+5, pNVRawData, NVRawDataLen, 1000);

is not correct because of ''+5'' (any garbage) but is working correct and reads correct value.

I'm using newest Cube & FW.

Why?

Whats wrong?
11 REPLIES 11
stm322399
Senior
Posted on September 26, 2014 at 18:39

Please consider using

I2C_MEMADD_SIZE_16BIT

that must return the same result than 

I2C_MEMADD_SIZE_8BIT

+5. (because of the way HAL tests this parameter).

Your EEPROM has 8-bit organization, which means that data is addressed 8-bit per address, and there are 32768 addresses, you need more than 8 bits to write an address, that's why you *must* use

I2C_MEMADD_SIZE_16BIT

.

Double check your datasheet, when you read data from EEPROM, you need to write the read pointer using two bytes, hence

I2C_MEMADD_SIZE_16BIT

.

dbo
Associate II

Hi,

I'm using HAL_I2c_Mem_Read(), too.

And may I ask if STM32's I2C can generate wave like the following picture. I have tryed Mem_read() and any other function in i2c.c , but the bit following device addres is "0",which means "write" in I2c.

May you help me out, thanks.

0690X000006D8D0QAK.jpg