标签:
AC24C32是Atmel的两线制串行EEPROM芯片,根据工作电压的不同,有-2.7、-1.8两种类型。主要特性有:
与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写入了一段字符串,之后将写入的信息反复读出。
1 /* 2 access to EEPROM AT24C32 using Arduino 3 storage capacity: 32K bits (4096 bytes) 4 */ 5 6 #include <Wire.h> 7 8 #define ADDRESS_AT24C32 0x50 9 10 word wordAddress = 0x0F00; //12-bit address, should not more than 4095(0x0FFF) 11 char str[] = "This is ZLBG."; //string size should not more than 32 and the buffer size 12 byte buffer[30]; 13 14 int i; 15 16 void setup() 17 { 18 Wire.begin(); 19 Serial.begin(9600); 20 21 //write 22 Wire.beginTransmission(ADDRESS_AT24C32); 23 Wire.write(highByte(wordAddress)); 24 Wire.write(lowByte(wordAddress)); 25 for (i = 0; i < sizeof(str); i++) 26 { 27 Wire.write(byte(str[i])); 28 } 29 Wire.endTransmission(); 30 31 delay(10); //wait for the internally-timed write cycle, t_WR 32 } 33 34 void loop() 35 { 36 //read 37 Wire.beginTransmission(ADDRESS_AT24C32); 38 Wire.write(highByte(wordAddress)); 39 Wire.write(lowByte(wordAddress)); 40 Wire.endTransmission(); 41 Wire.requestFrom(ADDRESS_AT24C32, sizeof(str)); 42 if(Wire.available() >= sizeof(str)) 43 { 44 for (i = 0; i < sizeof(str); i++) 45 { 46 buffer[i] = Wire.read(); 47 } 48 } 49 50 //print 51 for(i = 0; i < sizeof(str); i++) 52 { 53 Serial.print(char(buffer[i])); 54 } 55 Serial.println(); 56 57 delay(2000); 58 }
AT24C32 - Atmel Corporation
Arduino playground: Using Arduino with an I2C EEPROM
xAppSoftware Blog: How to interface the 24LC256 EEPROM to Arduino
标签:
原文地址:http://www.cnblogs.com/zlbg/p/4230137.html