I'm trying to figure out how to read just the mac address section of this chip using i2c... anyone have any ideas? I tried using wire library however it needs an address, etc.
// Wire Master Reader
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Reads data from an I2C/TWI slave device
// Refer to the "Wire Slave Sender" example for use with this
// Created 29 March 2006
#define I2C_ADDRESS 0x00
#include <Wire.h>
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(115200); // start serial for output
Serial.println("begin.");
}
void loop()
{
char myself = readRegister(0xFA);
Serial.print(myself);
delay(1000);
}
unsigned char readRegister(unsigned char r)
{
unsigned char v;
Wire.beginTransmission(I2C_ADDRESS);
Wire.send(r); // register to read
Wire.endTransmission();
Wire.requestFrom(I2C_ADDRESS, 1); // read a byte
while(!Wire.available())
{
// waiting
}
v = Wire.receive();
return v;
}
You need 4K7 pull ups on both the SDA and the clock line.
What are you getting back?
From that code you posted you should be reading back zero.
Reading other registers should give you:-
Register Contents
0xFB 0x04
0xFC 0xA3
These are fixed, the following should be unique to the device, the data sheet has:-
0xFD 0x12
0xFE 0x34
0xFF 0x56
using no resistors and using i2c address 0x50 or 0x51 and reading register 0xFB, I get back 255. I will try adding 4K7 pull ups to both clock and SDA and report back.
Ok. I put a 4.7k ohm pull up resister on both the SDA and SCL lines and still, I only get 255 using this code:
#include <Wire.h>
#define EEPROM_ADDR 0x50 // I2C Buss address of 24LC256 256K EEPROM
void setup(){
Wire.begin(); // join I2C bus (address optional for master)
Serial.begin(115200);
delay(500);
Serial.println("Reading Test:");
Serial.print(i2c_eeprom_read_byte(EEPROM_ADDR, 0xFC),DEC);
Serial.print(" ");
}
void loop(){
}
void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data ) {
int rdata = data;
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddress >> 8)); // Address High Byte
Wire.send((int)(eeaddress & 0xFF)); // Address Low Byte
Wire.send(rdata);
Wire.endTransmission();
}
// Address is a page address, 6-bit (63). More and end will wrap around
// But data can be maximum of 28 bytes, because the Wire library has a buffer of 32 bytes
void i2c_eeprom_write_page( int deviceaddress, unsigned int eeaddresspage, byte* data, byte length ) {
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddresspage >> 8)); // Address High Byte
Wire.send((int)(eeaddresspage & 0xFF)); // Address Low Byte
byte c;
for ( c = 0; c < length; c++)
Wire.send(data[c]);
Wire.endTransmission();
delay(10); // need some delay
}
byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {
byte rdata = 0xFF;
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddress >> 8)); // Address High Byte
Wire.send((int)(eeaddress & 0xFF)); // Address Low Byte
Wire.endTransmission();
Wire.requestFrom(deviceaddress,1);
if (Wire.available()) rdata = Wire.receive();
return rdata;
}
Anything else I need to do to get i2c working with the 24AA line of EEPROMs?