View previous topic :: View next topic |
Author |
Message |
pedro
Joined: 24 Apr 2009 Posts: 128
|
Posted: Sat Apr 16, 2011 2:04 pm Post subject: With Writeeeprom write a word var |
|
|
Hello,
Can't find any referenz on the help
Can i use a word var with readeeprom and writeeeprom instructions?
or must i first split the word in two bytes to write it on the inside Atmega cpu eeprom?
example what i want do:
dim w as word
writeeeprom w, 2
or must it be
writeeeprom high(w), 2
writeeeprom low(w), 3
Best regards
Pedro |
|
Back to top |
|
|
ex4
Joined: 13 Jan 2006 Posts: 1062 Location: indonesia
|
Posted: Sat Apr 16, 2011 5:20 pm Post subject: |
|
|
use ERAM variable type for your problem and everything is OK
example :
dim eram_dummy as eram byte at 0 'avr errata about eeprom
dim eram_word as eram word
dim tmpwx as word
'read the eram
tmpwx = eram_word
'write the eram/eeprom
eram_word = 1234
tmpwx = 1234
eram_word = tmpwx 'same thing |
|
Back to top |
|
|
proreha
Joined: 13 Aug 2010 Posts: 9
|
Posted: Sat Apr 16, 2011 7:18 pm Post subject: |
|
|
I use the Writeeprom command just as it is.
It occupies the bytes from the starting position, means, next position will be position +2.
Maybe it's not genious, but it works so far.
eg.
Pos1 = 0
Pos2 = 2
writeeprom var1, pos1
Writeeprom var2, pos2
readeeprom Var1, pos1
readeeprom var2, pos2
Christoph |
|
Back to top |
|
|
proreha
Joined: 13 Aug 2010 Posts: 9
|
Posted: Sat Apr 16, 2011 7:20 pm Post subject: |
|
|
I use the Writeeprom command just as it is.
It occupies two bytes from the starting position, means, next position will be position +2.
Maybe it's not genious, but it works so far.
eg.
Pos1 = 0
Pos2 = 2
writeeprom var1, pos1
Writeeprom var2, pos2
readeeprom Var1, pos1
readeeprom var2, pos2
Christoph |
|
Back to top |
|
|
pedro
Joined: 24 Apr 2009 Posts: 128
|
Posted: Sat Apr 16, 2011 8:07 pm Post subject: |
|
|
Hello proreha
I use it to, but for byte var, not tested with word var
I will try ex4 method and give than feedback
Pedro |
|
Back to top |
|
|
athomeelectronics
Joined: 13 Jun 2007 Posts: 60
|
Posted: Tue Apr 26, 2011 11:56 am Post subject: |
|
|
pedro wrote: | Hello proreha
I use it to, but for byte var, not tested with word var
I will try ex4 method and give than feedback
Pedro |
I've been using write/readeeprom with bytes, words and strings and works perfectly. When writing strings to eeprom, you must note that string takes one byte more space than it's lenght.
Word takes 2 bytes. For example, if you write a word variable to location 1, you can not write another to location 2. Next "free" location is in that case 3. |
|
Back to top |
|
|
ex4
Joined: 13 Jan 2006 Posts: 1062 Location: indonesia
|
Posted: Tue Apr 26, 2011 1:57 pm Post subject: |
|
|
with dim as eram variable
you dont need to know where the compiler put it, since it will automatically be calculated. try this, and try to read the eeprom value back with your downloader or you could use print :
Code: |
dim eram_dummy as eram byte at 0 'avr errata
dim eram_w1 as eram word
dim eram_str1 as eram string*3
dim eram_i1 as eram integer
dim str1 as string*4
dim w1 as word
dim i1 as integer
'test
'write
eram_w1 = 3456
eram_str1 = 'hei'
eram_integer = -234
'read
w1 = eram_w1
str1 = eram_str1
i1 = eram_i1
print w1;" -- ";str1;" -- ";i1
[quote][/quote] |
|
|
Back to top |
|
|
pedro
Joined: 24 Apr 2009 Posts: 128
|
Posted: Tue Apr 26, 2011 3:14 pm Post subject: |
|
|
Hello,
Yes, the readeeprom and writeeeprom instructions works with byte and word vars, have tested it
Regards
Pedro |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Apr 26, 2011 8:30 pm Post subject: |
|
|
yes, the advise from ex4 is a good one : use ERAM. This is not a real variable but can be used to read/write. It replaces the read/write eeprom. Under the hood it will use the same code from the mcs.lib, but you do not need to worry about the address of variables. _________________ Mark |
|
Back to top |
|
|
athomeelectronics
Joined: 13 Jun 2007 Posts: 60
|
Posted: Tue Apr 26, 2011 9:12 pm Post subject: |
|
|
albertsm wrote: | yes, the advise from ex4 is a good one : use ERAM. This is not a real variable but can be used to read/write. It replaces the read/write eeprom. Under the hood it will use the same code from the mcs.lib, but you do not need to worry about the address of variables. |
I've learned that if you have a program which you're constantly developing (and sending new versions to your customer) and there is hundreds of bytes of calibration values in eeprom, you really want to know which value is at where in the eeprom, because Bascom can't and won't always use exactly the same positions in between different compiles of your program (if you use ERAM). |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Apr 26, 2011 9:29 pm Post subject: |
|
|
That is not true.
If you add the new variables after the old ones, they will be added to new locations. You can simply verify this in the report.
Of course when you insert new variables between existing ones, you will get problems. But you will have them with read/write eeprom too.
While an internal created variables like _sec, _min, etc. could have a different location with a compiler update, (i said could!) this will never happen to ERAM variables.
So if you have this
dim a as eram byte
dim b as eram byte
it will remain always on location 0 and 1
And if your new eram var is here :
dim a as eram byte
dim new as eram byte
dim b as eram byte
then you see the problem.
but there is none if you do this :
dim a as eram byte
dim b as eram byte
dim new as eram byte _________________ Mark |
|
Back to top |
|
|
ex4
Joined: 13 Jan 2006 Posts: 1062 Location: indonesia
|
Posted: Wed Apr 27, 2011 3:08 am Post subject: |
|
|
for the calibration, i usually give pc calibration program to the client to save, update, or even clear it all, so no problem with that kind of problem |
|
Back to top |
|
|
athomeelectronics
Joined: 13 Jun 2007 Posts: 60
|
Posted: Wed Apr 27, 2011 9:01 am Post subject: |
|
|
albertsm wrote: | That is not true. |
Yes, I agree with you if you dim variables in order and never put anything in between, then you will not face problems.
Quote: |
And if your new eram var is here :
dim a as eram byte
dim new as eram byte
dim b as eram byte
then you see the problem.
but there is none if you do this :
dim a as eram byte
dim b as eram byte
dim new as eram byte |
Excactly, this is what I mean. I didn't mention this is "bad feature", one just has to live with it and know how it works if eram is used.
What is also, in my opinion, good in read/writeeeprom commands is that you can use them easily in loops. For example, if you want to format or clear eeprom or part of it. |
|
Back to top |
|
|
|