Reading and Writing integers to EEPROM

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
User avatar
ionize
Posts: 25
Joined: Fri Aug 05, 2011 8:01 pm
Has thanked: 29 times
Been thanked: 11 times
Contact:

Reading and Writing integers to EEPROM

Post 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
Attachments
Spa_D.fcfx
(64.54 KiB) Downloaded 203 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Reading and Writing integers to EEPROM

Post 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
Martin

User avatar
ionize
Posts: 25
Joined: Fri Aug 05, 2011 8:01 pm
Has thanked: 29 times
Been thanked: 11 times
Contact:

Re: Reading and Writing integers to EEPROM

Post by ionize »

Thanks Martin,
I'm trying to wrap my head around it.
Scott

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Reading and Writing integers to EEPROM

Post 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
Martin

User avatar
ionize
Posts: 25
Joined: Fri Aug 05, 2011 8:01 pm
Has thanked: 29 times
Been thanked: 11 times
Contact:

Re: Reading and Writing integers to EEPROM

Post 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
Attachments
Spa_D_1.fcfx
(68.49 KiB) Downloaded 198 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Reading and Writing integers to EEPROM

Post 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'.
Martin

User avatar
ionize
Posts: 25
Joined: Fri Aug 05, 2011 8:01 pm
Has thanked: 29 times
Been thanked: 11 times
Contact:

Re: Reading and Writing integers to EEPROM

Post 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
Attachments
Spa_D_3.fcfx
(67.51 KiB) Downloaded 213 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Reading and Writing integers to EEPROM

Post 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
Martin

User avatar
ionize
Posts: 25
Joined: Fri Aug 05, 2011 8:01 pm
Has thanked: 29 times
Been thanked: 11 times
Contact:

Re: Reading and Writing integers to EEPROM

Post 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

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Reading and Writing integers to EEPROM

Post 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:
Martin

Post Reply