0
Offline
Full Member
Karma: 1
Posts: 110
Arduino rocks
|
 |
« Reply #30 on: March 09, 2011, 05:58:47 pm » |
It is stored in address 0 1 and 2 i think. #include <EEPROM.h> template <class T> int EEPROM_writeAnything(int ee, const T& value) { const byte* p = (const byte*)(const void*)&value; int i; for ( i = 0; i < sizeof(value); i++) EEPROM.write(ee++, *p++); return i; }
template <class T> int EEPROM_readAnything(int ee, T& value) { byte* p = (byte*)(void*)&value; int i; for (i = 0; i < sizeof(value); i++) *p++ = EEPROM.read(ee++); return i; } void setup() { Serial.begin(9600); int reference = 323; int serial; EEPROM_writeAnything(0, reference); //EEPROM_readAnything(0,serial); serial = EEPROM.read(0) + EEPROM.read(1) + EEPROM.read(2); Serial.print(serial); } void loop() {}
serial = EEPROM.read(0) + EEPROM.read(1) + EEPROM.read(2); Removing read(2) will not give 323
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #31 on: March 09, 2011, 05:59:47 pm » |
It is stored in address 0 1 and 2 i think Think again.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
0
Offline
Full Member
Karma: 1
Posts: 110
Arduino rocks
|
 |
« Reply #32 on: March 09, 2011, 06:04:09 pm » |
serial = EEPROM.read(0) + EEPROM.read(1) + EEPROM.read(2); This 'prints' 323
serial = EEPROM.read(0) + EEPROM.read(1) This 'prints' 68
why then?? (And hehe i am on a laptop so shaking my keyboard wont make it that better :p)
tnnx
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35535
Seattle, WA USA
|
 |
« Reply #33 on: March 09, 2011, 06:05:01 pm » |
The value is not stored digit by digit in consecutive addressed. I think you need to go back and look at reply #11 (not to sound like a broken record or anything).
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 1
Posts: 110
Arduino rocks
|
 |
« Reply #34 on: March 09, 2011, 06:10:29 pm » |
"You provide the first EEPROM address to be written, and the functions return how many bytes were transferred." So if in this code it returns 2, meaning 2 bytes were transferred right?
But still I cannot understand the fact that using the code; EEPROM.read(0) + EEPROM.read(1) it 'prints' 68.
I'm sorry if im being such a bi*** but I really need to understand this
tnx again
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35535
Seattle, WA USA
|
 |
« Reply #35 on: March 09, 2011, 06:14:34 pm » |
The function returns the high byte and the low byte on the two calls. The integer is constructed by shifting the high byte 8 places to the left and adding the low byte, as was shown in reply #11. It is NOT constructed by simply adding the two bytes.
The values that you are getting are 1 and 67. Shifting the 1 8 places is equivalent to multiplying by 256. So, 256 + 67 = ? That's right. 323.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 1
Posts: 110
Arduino rocks
|
 |
« Reply #36 on: March 09, 2011, 06:18:59 pm » |
aaaaaaaaaaaaaa tnx!!!!!!
now for tomorrow to continue looking in this....
TNX ALL!!!
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #37 on: March 10, 2011, 04:27:52 am » |
serial = EEPROM.read(0) + EEPROM.read(1) + EEPROM.read(2); Removing read(2) will not give 323 In case you were wondering: 323 decimal = 0x0143 0x01 + 0x43 + 0xFF (the contents of address 2, because you haven't written anything to it) = 0x143 = 323.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
0
Offline
Full Member
Karma: 1
Posts: 110
Arduino rocks
|
 |
« Reply #38 on: March 10, 2011, 10:08:33 am » |
Another question pls...
If for example I need integer 1511. I thought that it would need 3 bytes but 2 are needed(serialmonitered it).
Reading addreses 0 and address 1 i get these values address 0 - 231 address 1 - 5
So my question is, (looking at reply11), 5 is the HIGH byte right? How is it worked out? Moving 5 - 101B to shift 8 places - 10100000000 - 1280?? Adding 231 = 1511
Is this right? tnx
|
|
|
|
|
Logged
|
|
|
|
|
Espoo, Finland
Offline
God Member
Karma: 6
Posts: 581
"Oops, try again..."
|
 |
« Reply #39 on: March 10, 2011, 10:57:04 am » |
What is 101B, where did it came from?
But if your high byte is 5, then 5 * 256 =1280. That is correct. 1280 + 231 =1511, so that is true as well.
Kari
|
|
|
|
|
Logged
|
The only law for me; Ohms Law: U=R*I P=U*I Note to self: "Damn! Why don't you just fix it!!!"
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #40 on: March 10, 2011, 11:06:40 am » |
What is 101B, where did it came from?
5 in binary. OP: Start thinking in hex. 1511 is 0x05E7, so two bytes only, 0x05 and 0xe7.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Espoo, Finland
Offline
God Member
Karma: 6
Posts: 581
"Oops, try again..."
|
 |
« Reply #41 on: March 10, 2011, 03:40:34 pm » |
What is 101B, where did it came from?
5 in binary. OP: Start thinking in hex. 1511 is 0x05E7, so two bytes only, 0x05 and 0xe7. I'm dummy. That "B" confused me, I though IT WAS hex 101B. I don't know how they should be expressed in these posts, I like to say "bin" or "hex" just to be sure, not combining binary and decimals in the same sentence.  Cheers, Kari EDIT. By the way, what does the "OP:" stand for? OT= off topic, but OP?
|
|
|
|
« Last Edit: March 10, 2011, 03:42:27 pm by GaryP »
|
Logged
|
The only law for me; Ohms Law: U=R*I P=U*I Note to self: "Damn! Why don't you just fix it!!!"
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #42 on: March 10, 2011, 03:43:46 pm » |
Original Poster
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Espoo, Finland
Offline
God Member
Karma: 6
Posts: 581
"Oops, try again..."
|
 |
« Reply #43 on: March 10, 2011, 03:54:56 pm » |
Original Poster
Ok, I though it was for me. This has been very enlighten conversation for me, only thing that bothers me is the short lifeline of the internal eeprom. If I decide to use external eeprom IC, is there anything that makes life easier or more complicated, comparing to internal eeprom? Is it faster or exactly opposite? Programming issues are more likely the biggest consern, not the speed. Cheers, Kari
|
|
|
|
|
Logged
|
The only law for me; Ohms Law: U=R*I P=U*I Note to self: "Damn! Why don't you just fix it!!!"
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #44 on: March 10, 2011, 03:57:07 pm » |
only thing that bothers me is the short lifeline of the internal eeprom. I thought the retention time was of the order of a century - do you plan on leaving your Arduino to your grandchildren?
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
|