Page 1 of 1

Reading and Writing integers to EEPROM

Posted: Thu Oct 23, 2014 12:02 am
by ionize
In the attached program, I've got most issues sorted, today, however, I found out that I didn't account for reading and writing numbers (which are minutes) up to 1440 to the EEPROM. Researching how to do it has left me confused (easy to do these days). The examples I have looked at are: http://www.matrixtsl.com/mmforums/viewt ... 26&t=15107 and http://www.matrixtsl.com/mmforums/viewt ... 26&t=11343. For starters, I'm Not sure how breaking the number into high byte and low byte is done when it can be changing up or down.
Please show me how to do it.
Many thanks to everyone for all the previous hints and helps.

Scott

Re: Reading and Writing integers to EEPROM

Posted: Thu Oct 23, 2014 1:12 pm
by medelec35
Hi Scott,
Have you read this thread?
ionize wrote: I'm Not sure how breaking the number into high byte and low byte is done when it can be changing up or down.
Breaking up can be done just before the saving to EEPROM & combining can be so as soon as both addresses containing High and low bytes are retrieved.

Martin

Re: Reading and Writing integers to EEPROM

Posted: Fri Oct 24, 2014 12:44 am
by ionize
Thanks Martin,
I'm trying to wrap my head around it.
Scott

Re: Reading and Writing integers to EEPROM

Posted: Fri Oct 24, 2014 11:21 am
by medelec35
Hi Scott,
Your welcome.
If you give it a go, then post flowchart, I will take a look at it for you.
I can also get it working then repost (if not already working).

Martin

Re: Reading and Writing integers to EEPROM

Posted: Sat Oct 25, 2014 12:12 am
by ionize
I think I added the code right but now the display is blanked or displays garbage from the start. Haven't had that problem before no matter how bad my code was. The rest of the program works as before. It works, I think, in simulation where the display can be seen but you cannot see whats in the EEPROM anymore like you could in V5. I know its the code corrupting because if I take it out, the OLED works fine. I can't see where the conflicts are.
Thanks,
Scott

Re: Reading and Writing integers to EEPROM

Posted: Sat Oct 25, 2014 9:56 am
by medelec35
Hi Scott,
ionize wrote:but you cannot see whats in the EEPROM anymore like you could in V5.
You can, you just select View menu then Console.
There will be an eeprom tab:
EEPROM Contents.png
(44.54 KiB) Downloaded 3068 times
As for your flowchart:
You are using a discussion branch (If OX_Ontime > 255) before reading from EEPROM.
You will need to read from EEPROM first.
The way I would do it is:

Code: Select all

Read highbyte from EEPROM

Code: Select all

Read Lowbyte from EEPROM

Code: Select all

If highbyte = 255 && Lowbyte = 255

Code: Select all

Yes:  OX_Ontime = 0

Code: Select all

No: OX_Ontime = ByteLow+(ByteHigh << 8) 
This is because if EEPROM has not been used all the default values are 255
I would use shift 8 places (<<8) rather than *256 as its more efficient.
I would also suggest the you select the eeprom component on the dashboard, right select properties, then remove all contents from 'Initial Values'.

Re: Reading and Writing integers to EEPROM

Posted: Sun Oct 26, 2014 8:31 pm
by ionize
I should have known EEPROM was improved just like everything else.
I believe I added your suggestions correctly and now it simulates well but won't compile: I get: error: invalid pragma DATA argument 'MX_UINT16'
when trying to write to the chip. Since the chart simulates, I don't have a clue on where this is or what it is. Any ideas, fixes, laughter?
Thanks,
Scott

Re: Reading and Writing integers to EEPROM

Posted: Sun Oct 26, 2014 10:15 pm
by medelec35
Hi Scott,
ionize wrote:won't compile: I get: error: invalid pragma DATA argument 'MX_UINT16'
That will be caused by an invalid entry in the

Code: Select all

Initial Values 
of the EEPROM properties.
Just click on the initial values entry box and make sure all data have been removed.
It looks like something is left within the box but it's invisible:
EEPROM1.png
(24.36 KiB) Downloaded 3053 times
As you can see I have highlighted it.
ionize wrote:Any ideas, fixes, laughter?
No laughter as something like like is very difficult to spot!

Another thing is you can't palace EEPROM, PWM or components with delays (including delays that would be used within a components) within interrupts.
If you do then you will get a stack corruption warning.
If ignored and the hardware appears to work, than at some point the hardware will fail.

Martin

Re: Reading and Writing integers to EEPROM

Posted: Thu Oct 30, 2014 4:39 am
by ionize
:D Well, I think I can put this baby to bed! It's working well now, thank you so much Martin. Your direction and advice as always, spot on.
All Hail THE PROFESSOR! :D
Scott

Re: Reading and Writing integers to EEPROM

Posted: Fri Oct 31, 2014 2:56 am
by medelec35
Thanks Scott,
I'm glad you are happy with the way it's all working.
Also thanks for the compliment, although there are people on these forums who are more like a professor than I am. :wink: