cancel
Showing results for 
Search instead for 
Did you mean: 

How to integrate the M24512 EEPROM in stm32f303?

MVENN.1
Associate II
 
2 REPLIES 2
MVENN.1
Associate II

I'm using m24512 eeprom chip in stm32f303 i'm not able write and read the data from eeprom can you please suggest me

this my code

SLAVE addres is :0xA0

void i2c_master_write(uint8_t devAddr, uint32_t memAddr, uint8_t *i2c_WriteBuf, uint32_t length )

{

//TODO call HAL_i2c_Write function here

gM24512_TxBuf[0] = memAddr;

gM24512_TxBuf[1] = 0;

gM24512_TxBuf[2] = 0;

/*##- Start the transmission process #####################################*/

// do

// {

if (HAL_I2C_Master_Transmit_IT(&hi2c2, (uint16_t)devAddr, (uint8_t *)gM24512_TxBuf, sizeof(gM24512_TxBuf)) != HAL_OK)

{

/* Error_Handler() function is called when error occurs. */

//vcnl4200_Error_Handler();

}

/*##- Wait for the end of the transfer #################################*/

/* Before starting a new communication transfer, you need to check the current

   state of the peripheral; if it’s busy you need to wait for the end of current

   transfer before starting a new one.

   For simplicity reasons, this example is just waiting till the end of the

   transfer, but application may perform other tasks while transfer operation

   is ongoing. */

while (HAL_I2C_GetState(&hi2c2) != HAL_I2C_STATE_READY)

{

}

please tell me anything i did miss

Hello

HAL_I2C_Mem_Read(...) and HAL_I2C_Mem_Write(...) functions are suitable for read and write to ser eeproms

uint8_t b[5];// define the buffer

HAL_I2C_Mem_Read(&hi2c, 0xA0, 0x0000, 2, b, sizeof(b), 100);// random read the first 5 bytes ( address=0)

parameters

hi2c is the I2C structure

0xA0 is the slave address (no need to shift 0x50<<1)

0x0000 is the adress of first byte (random addresses has 2 bytes)

2 is the length of the address (2 bytes long)

b is a pointer to buffer

sizeof(b) is the length of buffer

100 msec is the timeout for this operation if not succeed to return.. ( check the return value.)