Writing to and Reading from Flash Memory using 16F723

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

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

Writing to and Reading from Flash Memory using 16F723

Post by medelec35 »

I have created a new thread, so I don’t hijack the thread mytekcontrols started.
mytekcontrols wrote:For those that are following this, Ben just sent me some alternative C Code for Reading and Writing to the Flash Memory area on the PIC. Apparently there is a problem with getting the original examples to compile in FlowCode.

Here are the new versions:

Code: Select all

/* Read from Flash Memory
*/
volatile char* register_ptr = (char*)FCV_ADDR;
FCV_TEMP = *register_ptr;

/* Write to Flash Memory
*/
volatile char* register_ptr = (char*)FCV_ADDR;
*register_ptr = FCV_TEMP;
FCV_TEMP = byte to be written into Flash memory, or value that was read from Flash memory (from FlowCode this would be variable "TEMP").
FCV_ADDR = 16-bit integer for Flash memory address where byte will be written to, or read from (from FlowCode this would be variable "ADDR").

This code appears to compile properly, although I have yet to actually try to use it with real hardware.
Thank you for sharing this information. I am very interested in completing a small project to write and read from flash.
I have created a small test program. Unfortunately the the variable which is suppose to write to flash are volatile( in line with what mytekcontrols was saying), so contents are lost when power is re-applied. What I am trying to acheive is Read from ADC1 store ADC1 variable. Finaly read the stored ADC1 after power is removed and restablished.
I am trying to figure out reason, but any help is greatly appreciated as I am not getting very far. :cry:
Thank you in advance.
Martin

User avatar
Steve
Matrix Staff
Posts: 3434
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Re: Writing to and Reading from Flash Memory using 16F723

Post by Steve »

I had a quick search and this might be of help:
http://forum.sourceboost.com/index.php? ... c=4623&hl=

But... you might be on to a loser with this. In the datasheet for this device it specifically says "Processor Read Access to Program Memory" and there is a section on reading program memory values. However, there is no equivalent information on writing to program memory. I think this device does not have this capability.

In fact, there seems to be only a few 16F families that have this "self-write" functionality. You can perform a parametric search for devices here ("self-write is about the 6th one down):
http://www.microchip.com/ParamChartSear ... &pageId=74

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

Re: Writing to and Reading from Flash Memory using 16F723

Post by medelec35 »

Thanks Steve, I read the data sheet at the weekend, and also came to similar conclusion as you. So I have submitted a ticket to microchip, to ask the question.

The other way round is to use a 28 pin chip (hardware already designed) that is pin for pin compatible and has EEPROM like 16F882. The nearest target is 16F883, which is on the same data sheet (16F882/883/884/886/887). So I used 16F882, would there be an issue?
I am going copy the 16F883.fcd rename to 16F882, and change relevant settings. Only issue would then be PPP? I.e. setting configuration settings.
Do you think this is a possibility please?
Martin

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

Re: Writing to and Reading from Flash Memory using 16F723

Post by medelec35 »

Just tested with 16F882.FCD. Only failed because I have exceded the memory of the chip. So looks like 16F883 after all :P
At lest I know adding new FCD file was very easy in this case.
Martin

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

Re: Writing to and Reading from Flash Memory using 16F723

Post by medelec35 »

steve wrote:But... you might be on to a loser with this. In the datasheet for this device it specifically says "Processor Read Access to Program Memory" and there is a section on reading program memory values. However, there is no equivalent information on writing to program memory. I think this device does not have this capability.

In fact, there seems to be only a few 16F families that have this "self-write" functionality. You can perform a parametric search for devices here ("self-write is about the 6th one down):
http://www.microchip.com/ParamChartSear ... &pageId=74
Just letting you know, you was correct.
Had a reply from microchip stating it could not be done. I was under the wrong impression that all chips with flash can be used in this manor.
Thanks again anyway Steve.

Problem have been solved using 16F883. That can write to flash, and use EEPROM for storage. I have used the latter.
Now to solve last issue of watchdog timeout :p
Martin

Post Reply