2016-07-04 12:30 AM
Hi,
I am trying to read the content of an EEPROM,24AA02E48T, using HAL I2C library. There is an example for this task which has been done in SPL instead of HAL and can be found athttps://github.com/Catethysis/stm32_i2c. Since HAL library does not have all the SPL functions, its not trivial to port the code. In SPL, the code that reads the content of EEPROM is:void I2C_burst_read(I2C_TypeDef* I2Cx, uint8_t HW_address, uint8_t addr, uint8_t n_data, uint8_t *data)
{
while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY));
I2C_GenerateSTART(I2Cx, ENABLE);
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT));
I2C_Send7bitAddress(I2Cx, HW_address, I2C_Direction_Transmitter);
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
I2C_SendData(I2Cx, addr);
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
I2C_GenerateSTOP(I2Cx, ENABLE);
I2C_GenerateSTART(I2Cx, ENABLE);
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT));
I2C_Send7bitAddress(I2Cx, HW_address, I2C_Direction_Receiver);
while (!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
I2C_AcknowledgeConfig(I2Cx, ENABLE);
while(n_data--) {
if(!n_data) I2C_AcknowledgeConfig(I2Cx, DISABLE);
while (!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED));
*data++ = I2C_ReceiveData(I2Cx);
}
I2C_AcknowledgeConfig(I2Cx, DISABLE);
I2C_GenerateSTOP(I2Cx, ENABLE);
while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY));
}
Now, I am trying to read the EEPROM so I am trying to address it but
HAL_I2C_Mem_Write() always returns HAL_ERROR
:MX_I2C1_Init();
while((__HAL_I2C_GET_FLAG(&hi2c1, I2C_FLAG_BUSY) == SET));
while(HAL_I2C_Mem_Write(&hi2c1, (uint16_t)I2C_DEV_ADDR_WR, 0xFA, 2,(uint8_t *)aRxBuffer, 1, 2000)!= HAL_OK)
{
/* Error_Handler() function is called when Timout error occurs.
When Acknowledge failure ocucurs (Slave don't acknowledge it's address)
Master restarts communication */
if (HAL_I2C_GetError(&hi2c1) != HAL_I2C_ERROR_AF)
{
LED_Toggle(LED1);
HAL_Delay(100);
}
}
Is there any example that I can follow which uses HAL library to read from I2C EEPROM? How should I proceed? I really appreciate any help with this.
Best regards
#stm32f-i2c-eeprom
2016-07-04 01:44 AM
Hi,
You can find HAL I2C examples under ST web page within the STM32CubeXX firmware package.For example, the firmware package provides a full set of running examples showing how to use the I2C EEPROM under this path:STM32Cube_FW_L4_V1.5.0\Projects\STM32L476G_EVAL\Examples\I2CAlso, you can find I2C EEPROM example within the firmware package: STM32Cube_FW_F4_V1.12.0\Projects\STM32469I_EVAL\Examples\I2C\I2C_EEPROMRegards2016-07-04 01:55 AM
Hi jafari.alex,
You find ''I2C_EEPROM'' example un the at this path STM32Cube_FW_F7_V1.4.0\Projects\STM32756G_EVAL\Examples\I2C Note that the Hal examples are listed in a application note called ''STM32Cube firmware examples'' as . -Hannibal-