Pages: [1]   Go Down
Author Topic: EEPROM Issue  (Read 962 times)
0 Members and 1 Guest are viewing this topic.
Cleveland, TN
Offline Offline
Full Member
***
Karma: 2
Posts: 207
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am reading RFID tags and writing them to eeprom. I only had one on hand for the longest time and it reads and writes perfectly every time.

The tag number is 4D006A6F25

When I read the bytes back out of eeprom and compare them to the read it compares exactly with no issues.

To move beyond that, I got some more tags. These tags are all very similar in their numbering and here is an example:

840033789A

When I read the first byte back out it shows up as FFFFFF84 which of course will not compare to the read 84.

I suspect that it has to do with how I am writing to eeprom and everything worked for the first tag. So what is different?

Here is the code I use to write to eeprom:

Code:

for (int i = 0; i < 5; i++)
{
  EEPROM.write(eepromindex,code[i]);
  Serial.print("Index: ");
  Serial.print(eepromindex);
  Serial.print(",");
  Serial.println(code[i],HEX);
  eepromindex++;
}


code[] holds the 5 bytes of the tag id. eepromindex is simply indexed each time a write is made.

The result of the print is:

Index: 0,84
Index: 1,0
Index: 2,33
Index: 3,78
Index: 4,9A

When I do the compare to eeprom off of a subsequent read, I print the results of the bytes until I get the first failed match. These tags are failing on the first byte with the following serial print:

84:FFFFFF84

Help!

Logged

Luck,

Wade

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You are writing to EEPROM a byte apart when you are trying to write 5 bytes. So they will overlap. There is a library EEPROM Write Everything that will simplify what you are trying to do:

http://arduino.cc/playground/Code/EEPROMWriteAnything
Logged

Cleveland, TN
Offline Offline
Full Member
***
Karma: 2
Posts: 207
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm hearing you but I'm not following. The RFID tag is a 5 byte code, it is stored as a 5 byte character array code[].

If one eeprom write is for one byte and I increment the index each time, then I should be writing 1 byte of the code to the next byte of eeprom.

I clear the eeprom on startup. If I use the old tag, I can scan only it and it will read and write to eeprom. It will then compare correctly everytime. If I scan only one of the new tags, it will read the first time and write, after that it will not compare correctly. If I subsequently add the old tag, It will read and write to the next 6 eeprom bytes, and on subsequent scans of that tag, it will compare correctly to the second set of written data.

The point is that the old tag will work no matter what sequence of scanning tags. The new tags will never work.

Could it have something to do with the actual tag ID? I can't imagine why that would matter since it says it is writing the correct data.
« Last Edit: April 21, 2012, 01:05:08 am by Sacman » Logged

Luck,

Wade

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, to answer in more detail I would have to see the context. Like, all the code.
Logged

Cleveland, TN
Offline Offline
Full Member
***
Karma: 2
Posts: 207
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I will comment it all up and post it.

Thanks for the help Nick, I am stuck!

Logged

Luck,

Wade

Cleveland, TN
Offline Offline
Full Member
***
Karma: 2
Posts: 207
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So here is what I did. First, getting code to the web is a pain for me because my dev machine is not connected and everything else is wireless.

So as I started to go through and comment the code, I realized that I had overcomplicated the compare function. I was reading the values out and writing them to a temporary char array. So instead of doing that, I simply compared the code array byte by byte as I read the bytes from eeprom. This seems to be working. So whatever the problem was it was in how I was writing the data from eeprom to the temp char array.

Very weird but I will accept it.
Logged

Luck,

Wade

Offline Offline
Edison Member
*
Karma: 43
Posts: 1551
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
84:FFFFFF84
You are probably comparing an unsigned byte against a signed integer. When treated as a signed integer, the hex byte "84" is a negative number and when it is sign extended to a 32-bit signed integer it is "FFFFFF84".
We still need to see all your code.

Pete
Logged

Where are the Nick Gammons of yesteryear?

Pages: [1]   Go Up
Jump to: