ES Library Guide (I2c - Memory) - en
ES Library Guide (I2c - Memory) - en
)i2c_memory Library(
GitHub: Majid-Derhambakhsh
E-mail
1
Contents
Basic settings
Functions
Requirements …………………………………………………………………………………………………………………………. 7
To use this library, first add the c file to the program and include the following header.
#include "i2c_memory.h"
Memory Configuration
Edit the following values to adjust the IC code used and its address pins:
#define _AT24C04
#define _MEMORY_A0_PIN_STATE 0
#define _MEMORY_A1_PIN_STATE 0
#define _MEMORY_A2_PIN_STATE 0
#define _WP_DISABLE
I2C Configuration
First open the i2c_unit_conf.h file from the I2C_UNIT folder and edit the values below.
-- I2C Frequency.
-- I2C Unit prescaler (If not correct operation, edit with the values in Table 1-2):
ID Value
_PRE1 1
_PRE4 4
_PRE16 16
_PRE64 64
Table 1-2
2. I2C in ARM:
STM32 Series:
First open the stm32_i2c _conf.h file from the STM32_I2C folder and edit the values below.
#define STM32F1
#define _MEM_DEF_VAL_BUFF_LENGTH 50
-- Microcontroller Series.
-- Structure that contains the configuration information for the specified I2C.
Parameters -
Return values -
Example:
• I2C_Memory_Init();
I2C_MemoryIsReady
Parameters
Return values
Example:
• device_status = I2C_MemoryIsReady(100);
I2C_Memory_SingleWrite
Parameters
Return values
• _MEM_SIZE_ERROR
• AVR: _STAT_OK / _STAT_ERROR
• ARM: HAL_OK / HAL_ERROR
Example:
Function name uint8_t I2C_Memory_BurstWrite(uint32_t address, uint8_t *udata, uint32_t size, uint16_t time_out)
Parameters
Return values
• _MEM_SIZE_ERROR
• AVR: _STAT_OK / _STAT_ERROR
• ARM: HAL_OK / HAL_ERROR
Example:
I2C_Memory_SingleRead
Function description This function is used to read a byte of data from memory.
Parameters
Return values
• _MEM_SIZE_ERROR
• AVR: _STAT_OK / _STAT_ERROR
• ARM: HAL_OK / HAL_ERROR
Example:
I2C_Memory_BurstRead
Function name uint8_t I2C_Memory_BurstRead(uint32_t address, uint8_t *udata, uint32_t size, uint16_t time_out)
Function description This function is used to read a data string from memory.
Parameters
• _MEM_SIZE_ERROR
• AVR: _STAT_OK / _STAT_ERROR
• ARM: HAL_OK / HAL_ERROR
Example:
I2C_Memory_Erase
Function description This function is used to read a data string from memory.
Parameters
Return values
• _MEM_SIZE_ERROR
• AVR: _STAT_OK / _STAT_ERROR
• ARM: HAL_OK / HAL_ERROR
Example:
Requirement
Important tips
Error's:
• Chip or I2C Library not supported: This error occurs when the microcontroller or its
• Memory is not selected or not supported: This error occurs when the memory is not correctly
Warning's:
• Your Ax Pin state in not correct: This warning appears when the address pins
AT24C01 – AT24C02 – AT24C04 – AT24C08 – AT24C16 – AT24C32 – AT24C64 – AT24C128 – AT24C256 – AT24C512
AT24C1024
Memory blocks
0.8s
16s
9
Supported microcontroller's
ATmega & ATtiny series of AVR Microcontroller's with i2c_unit & gpio_unit driver's
All STM32 series of ARM Microcontroller's with HAL & stm32_i2c driver's
Version 0.0.1
--------------------------------------------------------------------------------------------------------------------------------------
Version 0.0.0
--------------------------------------------------------------------------------------------------------------------------------------
11