2022-06-03 12:25 AM
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;
}
}
2022-06-03 01:16 AM
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