初级会员
- 积分
- 154
- 金钱
- 154
- 注册时间
- 2024-6-22
- 在线时间
- 12 小时
|
IntroductionThis 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 EEPROMConnect 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 Operations1. Initialize I2CInitialize 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 EEPROMFunctions 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 Operations1. Page Write OperationThe EEPROM page write function allows writing multiple bytes of data at once, improving write efficiency.
c复制代码
#define EEPROM_PAGE_SIZE 64HAL_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 IncrementUse 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 LinkTo purchase related products, visit our Taobao store: EVASH Taobao Store.
WeChat Message TemplateDear 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 KitWe 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
|
|