Pages: [1]   Go Down
Author Topic: help regarding interfacing eeprom  (Read 630 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Code:

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]
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46042
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Was there a question that you meant to ask? What do you need help with?
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

actually when i execute the above program am not getting any output..even in the serial monitor(i tried to print the content in the memory).please tell me where I am making mistake.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am actually using a sanguino board and I am connecting pins 17 and 16 to sda and sclk of the eeprom and the eeprom am using is at24c32a.Please help me on this. I am not at all getting output in the serial monitor.
Logged

Pages: [1]   Go Up
Jump to: