badri89
Junior Member level 3
Hi I am trying to log the temperature sensor readings to an external eeprom(AT24c32a) using arduino and using the following program
I found that nothin is getting displayed in the serial monitor and data is not at all getting written in the external eeprom also.Am i missing something?please help me out.
---------- Post added at 20:13 ---------- Previous post was at 19:50 ----------
In the datasheet of the eeprom it is given as
The 32K/64K is internally organized as 128/256 pages of 32 bytes each. Random word addressing requires a 12/13-bit data
word address.
So does this mean the address is 12 bits for my program..so instead of >>8 it should be >>6 and similarly for 0xff??please clarify me.
Code:
#include <Wire.h>
int pin=0;
void i2cexeepromwrite(int slaveaddress,int whichaddress,int data)
{
Wire.beginTransmission(slaveaddress);
Wire.send(whichaddress>>8);
Wire.send(whichaddress & 0xFF);
Wire.send(data);
Wire.endTransmission();
delay(100);
}
byte i2cexeepromread(int slaveaddress,int whichaddress)
{
int res;
Wire.beginTransmission(slaveaddress);
Wire.send((byte)whichaddress>>8);
Wire.send((byte)whichaddress & 0xFF);
Wire.endTransmission();
Wire.requestFrom(slaveaddress,1);
if(Wire.available())
res=Wire.receive();
return res;
}
void setup()
{
Wire.begin();
Serial.begin(9600);
}
void loop()
{
int val,a;
float temp;
val=analogRead(pin);
temp=(5*val*100)/1024;
Serial.println(temp);
for(a=0;a<10;a++)
{
Serial.println("Writing now");
i2cexeepromwrite(0x50,a,temp);
Serial.println("Now Read");
i2cexeepromread(0x50,a);
}
}
I found that nothin is getting displayed in the serial monitor and data is not at all getting written in the external eeprom also.Am i missing something?please help me out.
---------- Post added at 20:13 ---------- Previous post was at 19:50 ----------
In the datasheet of the eeprom it is given as
The 32K/64K is internally organized as 128/256 pages of 32 bytes each. Random word addressing requires a 12/13-bit data
word address.
So does this mean the address is 12 bits for my program..so instead of >>8 it should be >>6 and similarly for 0xff??please clarify me.