AT24C02 EEPROM Memory
Module Source
Purchase Link: https://detail.tmall.com/item.htm?abbucket=0&id=698591628199&ns=1&spm=a21n57.1.0.0.7edf523co7QMUt
Baidu Netdisk Download Link:
https://pan.baidu.com/s/1MotE_ffwvoBPeFRveZ6rIw
Password:6666
Specifications
Operating Voltage: 1.8V-5.5V
Operating Current: Maximum 3mA
Communication Interface: I2C
Memory: 2048 bits
Clock Speed: Maximum 1000kHz at 5V, 400kHz for other voltages
Hardware Connection
- VCC: Connect to the 5V pin of the development board.
- GND: Connect to the GND pin of the development board.
- SDA (Serial Data Line): Connect to the A4 (SDA) pin of the development board.
- SCL (Serial Clock Line): Connect to the A5 (SCL) pin of the development board.
Usage Method
c
/******************************************************************************
* Test Hardware: LCSC ColorEasyDuino Development Board
* Version Number: V1.0
* Modified By: www.lckfb.com
* Modification Date: April 18, 2024
* Function Overview:
*****************************************************************************
* Open-source development board hardware and software information and related projects hardware and software information on official website
* Development board official website: www.lckfb.com
* Technical support resident forum, any technical problems are welcome at any time to exchange learning
* LCSC Forum: club.szlcsc.com
* Follow our Bilibili account: [立创开发板], stay toned to our latest news!
* We focus on cultivating Chinese engineers rather than profiting from board sales.
******************************************************************************/
#include <Wire.h>
#define EEPROM_ADDRESS 0x50 // AT24C02的I2C地址
void setup() {
Wire.begin(); // 初始化I2C通信
Serial.begin(9600); // 开始串行通信以观察结果
writeEEPROM(EEPROM_ADDRESS, 0, 123); // 将数字123写入AT24C02的地址0
delay(100); // 短暂延时以确保写入完成
int value = readEEPROM(EEPROM_ADDRESS, 0); // 从地址0读取值
Serial.print("Read value: ");
Serial.println(value); // 打印读取的值
}
void loop() {
// 在这个例子中不执行操作
}
void writeEEPROM(int deviceaddress, unsigned char eeaddress, byte data ) {
Wire.beginTransmission(deviceaddress);
Wire.write(eeaddress); // EEPROM字节
Wire.write(data);
Wire.endTransmission();
delay(5); // 等待写入完成
}
byte readEEPROM(int deviceaddress, unsigned char eeaddress ) {
byte rdata = 0xFF;
Wire.beginTransmission(deviceaddress);
Wire.write(eeaddress); // EEPROM字节
Wire.endTransmission();
Wire.requestFrom(deviceaddress, 1); // 请求1字节的数据
if (Wire.available()) rdata = Wire.read();
return rdata;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56