Mastering STM32 and EV24C MCU + EEPROM (ST + EVASH)

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:

  1. VDD (development board) to VDD (EEPROM)
  2. GND (development board) to GND (EEPROM)
  3. SCL (development board) to SCL (EEPROM)
  4. 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:

  1. Company Name
  2. Project Name
  3. 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

Mastering STM32指的是对STM32微控制器进行深入学习和掌握。STM32是由意法半导体公司(STMicroelectronics)推出的一系列32位单片机产品。在现代嵌入式系统中,STM32被广泛应用于各种领域,包括工业自动化、智能家居、医疗设备和消费电子等。要掌握STM32,我们需要了解其体系结构、硬件和软件方面的知识。 首先,我们需要熟悉STM32的体系结构。STM32是基于ARM Cortex-M内核设计的微控制器,因此我们需要了解Cortex-M内核的特性和寄存器结构。同时,还需要学习STM32微控制器的不同系列和型号,以及它们的功能和特性。这将帮助我们选择适合特定应用的微控制器。 其次,我们需要掌握STM32的硬件方面知识。这包括了解GPIO、外设接口(如UART、SPI和I2C)、模拟模块(如ADC和DAC)以及时钟和复位控制等。此外,还需要了解如何设计电路板和连接外围设备以与STM32通信。 最重要的是,我们需要学习STM32的软件开发。STM32提供了一套丰富的软件开发工具和库,如STM32CubeMX和STM32 HAL库。这些工具和库可以简化开发过程并提高效率。我们需要学会如何使用这些工具和库来配置微控制器,编写驱动程序和应用程序。同时,还需要了解如何使用调试工具和IDE(集成开发环境)来调试和测试STM32应用程序。 总之,要精通STM32,我们需要系统地学习其体系结构、硬件和软件方面的知识。通过深入理解STM32,我们可以开发出高效、可靠的嵌入式系统,并为各行各业提供解决方案。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值