![](https://s5-media.51cto.com/ost/pc/static/noavatar.gif)
回复
AC24C32主要特性
AC24C32是Atmel的两线制串行EEPROM芯片,根据工作电压的不同,有-2.7、-1.8两种类型。主要特性有:
管脚定义
与Arduino的连接
与Arduino UNO的I2C接口连接。
VCC连接5V;GND连接GND;AC24C32的SCL连接UNO的A5(SCL);AC24C32的SDA连接UNO的A4(SDA)。
功能调试
1. Page Write时,一次最多写入32个字节。当地址到达该页末尾时,会自动roll over到同一页的起始地址。
2. Sequential Read时,没有连续读取的字节数目限制(实际受限于Arduino的Wire库中buffer的大小)。当地址到达最后一页的末尾时,会自动roll over到首页的起始地址。
3. 写操作时,MCU发送stop后,AC24C32还需要一段tWR时间(tWR在5V供电时最大为10ms)进行内部工作,之后数据才正确写入。在tWR时间内,芯片不会回应任何接口的操作。
测试代码
以下代码向AC24C32写入了一段字符串,之后将写入的信息反复读出。
/*
access to EEPROM AT24C32 using Arduino
storage capacity: 32K bits (4096 bytes)
*/
#include <Wire.h>
#define ADDRESS_AT24C32 0x50
word wordAddress = 0x0F00; //12-bit address, should not more than 4095(0x0FFF)
char str[] = "This is ZLBG."; //string size should not more than 32 and the buffer size
byte buffer[30];
int i;
void setup()
{
Wire.begin();
Serial.begin(9600);
//write
Wire.beginTransmission(ADDRESS_AT24C32);
Wire.write(highByte(wordAddress));
Wire.write(lowByte(wordAddress));
for (i = 0; i < sizeof(str); i++)
{
Wire.write(byte(str[i]));
}
Wire.endTransmission();
delay(10); //wait for the internally-timed write cycle, t_WR
}
void loop()
{
//read
Wire.beginTransmission(ADDRESS_AT24C32);
Wire.write(highByte(wordAddress));
Wire.write(lowByte(wordAddress));
Wire.endTransmission();
Wire.requestFrom(ADDRESS_AT24C32, sizeof(str));
if(Wire.available() >= sizeof(str))
{
for (i = 0; i < sizeof(str); i++)
{
buffer[i] = Wire.read();
}
}
//print
for(i = 0; i < sizeof(str); i++)
{
Serial.print(char(buffer[i]));
}
Serial.println();
delay(2000);
}