cancel
Showing results for 
Search instead for 
Did you mean: 

hi, we are interfacing EEPROM to STM32L496ZG Nucleo board .but AT24C256 is failing to write data. Please find attached function to write data in EEPROM.We used A0 Device address to write data in EEPROM.Kindly Reply.

Namita
Associate II

int at24_HAL_WriteBytes(I2C_HandleTypeDef *hi2c,uint16_t DevAddress,uint16_t MemAddress, uint8_t *pData,uint16_t TxBufferSize)

{

if(HAL_I2C_Mem_Write(hi2c,(uint16_t)DevAddress,(uint16_t)MemAddress,I2C_MEMADD_SIZE_8BIT,pData,(uint16_t)TxBufferSize,1000)== HAL_OK)

{

#if 1//TEST_DEBUG

sprintf((char *)&g_uc_Txbuffer[0],"\r\nS");

Fn_PutStr(g_uc_Txbuffer);

      #endif//TEST_DEBUG

}

else

{

  #if 1//TEST_DEBUG

sprintf((char *)&g_uc_Txbuffer[0],"\r\nE");

Fn_PutStr(g_uc_Txbuffer);

      #endif//TEST_DEBUG

}

//if(HAL_I2C_IsDeviceReady(&hi2c1, 0xA0, 1, HAL_MAX_DELAY) == HAL_OK)

while(HAL_I2C_IsDeviceReady(hi2c, 0xA0, 1, HAL_MAX_DELAY) != HAL_OK);

//{

HAL_Delay(10);

if(HAL_I2C_Master_Transmit(hi2c, (uint16_t)DevAddress, (uint8_t) *pData, (uint8_t)TxBufferSize, HAL_MAX_DELAY)== HAL_OK)

{

  #if 1//TEST_DEBUG

sprintf((char *)&g_uc_Txbuffer[0],"\r\nSW");

Fn_PutStr(g_uc_Txbuffer);

      #endif//TEST_DEBUG

// return 1;

}

else

{

  #if 1//TEST_DEBUG

sprintf((char *)&g_uc_Txbuffer[0],"\r\nError");

Fn_PutStr(g_uc_Txbuffer);

      #endif//TEST_DEBUG

return 0;

}

}

1 REPLY 1
gbm
Lead III

24C256 requires 2-byte address -> I2C_MEMADD_SIZE_16BIT

You can only write no more than a single page of memory at once - see the memory datasheet, it's 64 bytes; definitely less than 1000 bytes you are trying to write.

Use HAL_I2C_Mem_Write() and HAL_I2C_Mem_Read() for interaction with 24C memories

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice