hi I am trying to interface my eeprom(atmel at24c32) with my sanguino board.My goal is to write the first 10 analog values produced by my lm35sensor to the eeprom.I surfed and used up the i2c library.The following is the code I am using.
int pin=0;
#include <Wire.h> //I2C library
void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data ) {
int rdata = data;
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddress >> 8)); // MSB
Wire.send((int)(eeaddress & 0xFF)); // LSB
Wire.send(rdata);
Wire.endTransmission();
}
byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {
byte rdata = 0xFF;
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddress >> 8)); // MSB
Wire.send((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(deviceaddress,1);
if (Wire.available()) rdata = Wire.receive();
return rdata;
}
void setup()
{
//char somedata[] = "this is data from the eeprom"; // data to write
Wire.begin(); // initialise the connection
Serial.begin(9600);
// i2c_eeprom_write_page(0x50, 0, (byte *)somedata, sizeof(somedata)); // write to EEPROM
//delay(10); //add a small delay
//Serial.println("Memory written");
}
void loop()
{
int val,i,temp;
byte b;
int addr=0;
val=analogRead(pin);
temp=(5*val*100)/1024;
// byte b = i2c_eeprom_read_byte(0x50, 0); // access the first address from the memory
for(i=0;i<10;i++)
{
addr++;
i2c_eeprom_write_byte( 0xa0,addr,temp);
//increase address
b = i2c_eeprom_read_byte(0xa1, addr);
Serial.println(b); //access an address from the memory
}
//Serial.println(temp);
delay(2000);
}
[code]
But I am not getting any output.please help me with this
[/code]