Arduino and I2C–the 24C65

The 24c65 is a great little 8-pin serial EEprom chip with 8k of  EPROM in it – so if you want some extra memory to store stuff in your Arduino board or similar – this would appear to be a nice chip – except that the standard Arduino library uses 7-bit addressing.

WHAT????? Yup, it’s for small devices with a few memory locations – whereas accessing several KB of addresses needs a 16 bit address! Also the Arduino library is a tad, erm, LARGE so off I went to find a replacement.

I stumbled on this… http://dsscircuits.com/articles/arduino-i2c-master-library.html  and that’s nice, a tight library for controlling EEPROMs but again this does not handle the larger variety… but down at the bottom of the blog, somewhat hidden in with my stupid questions is this… An EEPROM library with 16 bit addressing. Not only THAT but if you compile it into a little “Hello World” writer and reader, you are looking at 3234 bytes including the library. NICE!

Check out this code – it’s a bit rubbish as the printout doesn’t check for zero at the end of the string…. but it works… there is also the 24C256 which gives you 64k to play with…. that’s a lot of logging!!!  I’m sure it would not take too long to write some wrapper routines around this lot. Incidentally the chips have 3 address lines normally tied to ground – so you can fasten up to 8 of them together – so addressing half a meg of data would be no big deal and with a tiny library.

By default internal pullups are enabled so you don’t even need resistors if the leads are short – just power (will work regardless if you’re on 5v or 3v3), ground and 2 pins – that’s A4 and A5. What could be easier. Incidentally you DO need that delay after the first write (which takes much longer than a read – or the second one will fail – there is no check that I can see. (I tried I2c.available() and it just locked up). You can write up to 32 bytes at a time as that is the internal buffer size of the chip – if you wanted to write more, a simple function call would easily split the data up.

 

#include <I2C.h>

void setup()
{
Serial.begin(57600);
I2c.begin();
I2c.setSpeed(1);
I2c.write(0x50,1000,"Replaced here");
delay(10);
I2c.write(0x50,2000,"and replaced here");
delay(10);
}

void loop()
{
Serial.println("Starting");
I2c.read(0x50,1000,30);
while (I2c.available())
{
Serial.print((char)I2c.receive());
}
Serial.println("");
I2c.read(0x50,2000,30);
while (I2c.available())
{
Serial.print((char)I2c.receive());
}
Serial.println("");

}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s