Introduction
This guide aims to help you get started with the STM32 microcontroller and EVASH's EV24C series EEPROM chip. Through this tutorial, you'll learn how to use these components in practical projects, from basic to advanced techniques.
Required Materials
- STM32 development board (e.g., STM32F103C8T6)
- EVASH EV24C256A EEPROM development kit
- Connecting wires (DuPont lines)
- Basic electronic tools (soldering iron, multimeter, etc.)
Connecting the Development Board to EEPROM
Connect the STM32 development board to the EV24C256A EEPROM development board as follows:
- VDD (development board) to VDD (EEPROM)
- GND (development board) to GND (EEPROM)
- SCL (development board) to SCL (EEPROM)
- SDA (development board) to SDA (EEPROM)
Basic Operations
1. Initialize I2C
Initialize the I2C interface on the STM32:
c
复制代码
#include "stm32f1xx_hal.h" I2C_HandleTypeDef hi2c1; void MX_I2C1_Init(void) { hi2c1.Instance = I2C1; hi2c1.Init.ClockSpeed = 100000; hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2; hi2c1.Init.OwnAddress1 = 0; hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; hi2c1.Init.OwnAddress2 = 0; hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; if (HAL_I2C_Init(&hi2c1) != HAL_OK) { // Initialization Error Error_Handler(); } }
2. Read/Write EEPROM
Functions to read and write to the EEPROM:
c
复制代码
HAL_StatusTypeDef EEPROM_Write(uint16_t MemAddress, uint8_t *pData, uint16_t Size) { return HAL_I2C_Mem_Write(&hi2c1, EEPROM_ADDRESS, MemAddress, I2C_MEMADD_SIZE_16BIT, pData, Size, HAL_MAX_DELAY); } HAL_StatusTypeDef EEPROM_Read(uint16_t MemAddress, uint8_t *pData, uint16_t Size) { return HAL_I2C_Mem_Read(&hi2c1, EEPROM_ADDRESS, MemAddress, I2C_MEMADD_SIZE_16BIT, pData, Size, HAL_MAX_DELAY); }
Advanced Operations
1. Page Write Operation
The EEPROM page write function allows writing multiple bytes of data at once, improving write efficiency.
c
复制代码
#define EEPROM_PAGE_SIZE 64 HAL_StatusTypeDef EEPROM_PageWrite(uint16_t MemAddress, uint8_t *pData, uint16_t Size) { uint16_t remaining = Size; while (remaining > 0) { uint16_t write_size = remaining > EEPROM_PAGE_SIZE ? EEPROM_PAGE_SIZE : remaining; if (HAL_I2C_Mem_Write(&hi2c1, EEPROM_ADDRESS, MemAddress, I2C_MEMADD_SIZE_16BIT, pData, write_size, HAL_MAX_DELAY) != HAL_OK) { return HAL_ERROR; } remaining -= write_size; pData += write_size; MemAddress += write_size; HAL_Delay(5); // Delay to ensure write completion } return HAL_OK; }
2. Sequential Read with Auto Address Increment
Use the auto address increment feature to read continuous data from the EEPROM.
c
复制代码
HAL_StatusTypeDef EEPROM_SequentialRead(uint16_t MemAddress, uint8_t *pData, uint16_t Size) { return HAL_I2C_Mem_Read(&hi2c1, EEPROM_ADDRESS, MemAddress, I2C_MEMADD_SIZE_16BIT, pData, Size, HAL_MAX_DELAY); }
Taobao Store Link
To purchase related products, visit our Taobao store: EVASH Taobao Store.
WeChat Message Template
Dear Customer,
We are excited to offer a special promotion, giving away EVASH Ultra EEPROM Development Kits for free, including software code. The first 500 kits are free!
To claim your kit, please provide:
- Company Name
- Project Name
- Contact Person
We look forward to your response!
EVASH Team
Visit our website at evash.top and Taobao store at link.
Contact Information for Free Dev Kit
We are pleased to introduce our EVASH Ultra EEPROM Development Kit. We are giving away the first 500 kits for free, including software code.
To receive your free kit, please provide your company name, project name, and contact person.
For more information, visit evash.top.
Best regards, EVASH Team