Reading and Writing integers to EEPROM
Moderator: Benj
Reading and Writing integers to EEPROM
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
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 240 times
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Reading and Writing integers to EEPROM
Hi Scott,
Have you read this thread?
Martin
Have you read this thread?
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.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.
Martin
Martin
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Reading and Writing integers to EEPROM
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
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
Re: Reading and Writing integers to EEPROM
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
Thanks,
Scott
- Attachments
-
- Spa_D_1.fcfx
- (68.49 KiB) Downloaded 224 times
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Reading and Writing integers to EEPROM
Hi Scott,
There will be an eeprom tab: 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:
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'.
You can, you just select View menu then Console.ionize wrote:but you cannot see whats in the EEPROM anymore like you could in V5.
There will be an eeprom tab: 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)
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
Re: Reading and Writing integers to EEPROM
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
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 247 times
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Reading and Writing integers to EEPROM
Hi Scott,
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: As you can see I have highlighted it.
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
That will be caused by an invalid entry in theionize wrote:won't compile: I get: error: invalid pragma DATA argument 'MX_UINT16'
Code: Select all
Initial Values
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: As you can see I have highlighted it.
No laughter as something like like is very difficult to spot!ionize wrote:Any ideas, fixes, laughter?
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
Re: Reading and Writing integers to EEPROM

All Hail THE PROFESSOR!

Scott
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Reading and Writing integers to EEPROM
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.
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.

Martin