您现在的位置是:网站首页> 硬件
AT24C256存储模块
- 硬件
- 2021-03-28
- 835人已阅读
1.板载芯片AT24C256进口芯片;
2.板载I2C通讯所需的上拉电阻;
3.所有管脚均引出并标注;
4.PCB板子尺寸:1.9(CM)x1.1(CM)
模块电原理图
/*
【Arduino】168种传感器模块系列实验(资料+代码+图形+仿真)
实验六十八:AT24C256 I2C接口 EEPROM 存储模块 IIC
*/
#include <Wire.h>
#define ADDRESS_AT24C256 0x50
word wordAddress = 0x0F00;
char str[] = "This is ZLBG.";
byte buffer[30];
int i;
void setup()
{
Wire.begin();
Serial.begin(9600);
//write
Wire.beginTransmission(ADDRESS_AT24C256);
Wire.write(highByte(wordAddress));
Wire.write(lowByte(wordAddress));
for (i = 0; i < sizeof(str); i++)
{
Wire.write(byte(str));
}
Wire.endTransmission();
delay(10);
}
void loop()
{
Wire.beginTransmission(ADDRESS_AT24C256);
Wire.write(highByte(wordAddress));
Wire.write(lowByte(wordAddress));
Wire.endTransmission();
Wire.requestFrom(ADDRESS_AT24C256, sizeof(str));
if(Wire.available() >= sizeof(str))
{
for (i = 0; i < sizeof(str); i++)
{
buffer = Wire.read();
}
}
for(i = 0; i < sizeof(str); i++)
{
Serial.print(char(buffer));
}
Serial.println();
delay(2000);
}
/*
【Arduino】168种传感器模块系列实验(资料+代码+图形+仿真)
实验六十八:AT24C256 I2C接口 EEPROM 存储模块 IIC
程序之二
*/
#include <Wire.h>
#define EEPROM_ADDR 0x50
void setup()
{
Wire.begin();
Serial.begin(9600);
// TESTS FOR EACH FUNCTION BEGIN HERE
Serial.println("Writing Test:");
for (int i=0; i<20; i++){
i2c_eeprom_write_byte(EEPROM_ADDR,i,i+65);
Serial.print(". ");
delay(10);
}
Serial.println("");
delay(500);
Serial.println("Reading Test:");
for (int i=0; i<20; i++){
Serial.write(i2c_eeprom_read_byte(EEPROM_ADDR, i));
Serial.print(" ");
}
byte PageData[30];
byte PageRead[30];
for (int i=0; i<30; i++){
PageData = 0;
PageRead = 0;
}
Serial.println("");
for (int i=0; i<30; i++) PageData = i+33;
Serial.println("Writing Page Test:");
i2c_eeprom_write_page(EEPROM_ADDR, 100, PageData, 28 );
Serial.println("Reading Page Test:");
i2c_eeprom_read_buffer( EEPROM_ADDR, 100, PageRead, 28);
for (int i=0; i<28; i++){
Serial.write(PageRead);
Serial.print(" ");
}
}
void loop()
{
}
void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data )
{
int rdata = data;
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8));
Wire.write((int)(eeaddress & 0xFF));
Wire.write(rdata);
Wire.endTransmission();
}
void i2c_eeprom_write_page
( int deviceaddress, unsigned int eeaddresspage, byte* data, byte length )
{
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddresspage >> 8));
Wire.write((int)(eeaddresspage & 0xFF));
byte c;
for ( c = 0; c < length; c++)
Wire.write(data[c]);
Wire.endTransmission();
delay(10);
}
byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress )
{
byte rdata = 0xFF;
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8));
Wire.write((int)(eeaddress & 0xFF));
Wire.endTransmission();
Wire.requestFrom(deviceaddress,1);
if (Wire.available()) rdata = Wire.read();
return rdata;
}
void i2c_eeprom_read_buffer( int deviceaddress, unsigned int eeaddress, byte *buffer, int length )
{
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8));
Wire.write((int)(eeaddress & 0xFF));
Wire.endTransmission();
Wire.requestFrom(deviceaddress,length);
for ( int c = 0; c < length; c++ )
if (Wire.available()) buffer[c] = Wire.read();
}