Go Down

Topic: 24C32 EEPROM - strange results - Solved (Read 3227 times) previous topic - next topic

3zuli

Jul 10, 2013, 09:55 pm Last Edit: Jul 11, 2013, 11:34 am by 3zuli Reason: 1
Hello guys, my first post here.
I'm trying to build a device that will turn some outputs on and off at a scheduled time, based on a list of events. It's communicating via UART and accepts commands, such as "get_time", "help" (prints list of commands) or "set_pin <pin> <HIGH/LOW>". I'm using the Tiny RTC board (DS1307) which also has the 24C32 eeprom on it and I want to use it to store the list of scheduled tasks (higher capacity, more E/W cycles than in ATmega). Right now I'm testing it on Arduino Duemilanove, but the final thing will run on Uno R3.
I'm using this library to access the eeprom via I2C: http://www.idreammicro.com/svn/idreammicro-arduino/trunk/libraries/Eeprom24C32_64/. I first run the test sketch, which fills the eeprom with ASCII characters and then reads it - this worked just fine.
Then I wanted to print the entire eeprom's content via serial, in the format: <line number> <byte0> <byte1> ... <byte7> \n, so I wrote this piece of code
Code: [Select]

#include <Wire.h>
#include "RTClib.h"
#include <Eeprom24C32_64.h>
#define EEPROM_ADDRESS 0x50
static Eeprom24C32_64 eeprom(EEPROM_ADDRESS);

//other code here

//in void loop():
if(inputString=="read_eeprom\n"){              
            byte line[8]={0};
            byte a;
            for(int i=0;i<4000;i++){                                    
                eeprom.readBytes(i*8,8,line);                //start address, length (number of bytes to read), buffer to write into
                Serial.print(i+" ");
                for(a=0;a<=7;a++){
                    if(a==7) {Serial.println(line[a]);}
                             else {Serial.print(line[a]+" ");}
                }
            }

       }
   //help code here

After this, there is another piece of code, which after the "help" command sends some text via serial. It consists of about 20 Serial.println commands, that show you the help (info, list of serial commands...).
The strange part is, that when I send the read_eeprom command, arduino starts sending out "random" parts of the help code. It starts by printing the second line which contains my contact info, 8 times into one line, then goes to new line and does the same, but the overall length of the line is decreased by 1 character with each new line. It does this until it just prints nothing and then starts again, with a different line from the help. I have no idea how this happens. I tried to change the name "eeprom" to something else, but with the same result.
This is my first time working with eeprom's, so I am a bit confused about the adressing and I think I messed up the readBytes part. If I understand correctly, the memory is divided into 4000 pages, each page = 8 bits = 1 byte, therefore the total capacity is 4000 (4K) bytes (=32000 bits) and the smallest ammount of memory I can address/read from/write to is 1 byte. If that is true, it should be for(int i=0;i<4000;i+=8) and eeprom.readBytes(i,8,line);. Am I right?
Or am I missing something? Please help me on this. Thank you.
Edit: I just tried the fix I mentioned above, with the same results. I attached the entire output I get after I enter the command.

Edit 2: Ok, it seems that I solved the problem. Turns out that this caused the problem,
Code: [Select]
Serial.print(i+" ");
as I wanted to have a space character after I print the adress. After replacing it with
Code: [Select]
Serial.print(i);
Serial.print(": ");

everything works as it should.
However, I still have no idea how did the help part get into the serial.

Go Up