View previous topic :: View next topic |
Author |
Message |
Tronic19
Joined: 03 May 2022 Posts: 6
|
PIC16F157x How to flash read-write on it ? 128 bytes HEF |
Posted: Wed May 04, 2022 1:18 am |
|
|
Hi to all,
On classic PICs i use the integrated functions from CCS.
But actually, i need to read and write some bytes (non-volatile) with a PIC16F1578...
Does someone got a library to do that ? It seems really tricky ?
I need ideally for now only to access the High Endurance Flash Data Memory (HEF) at this area: 128 bytes if non-volatile data storage.
Thanks a lot for your all help ;) |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Wed May 04, 2022 2:55 am |
|
|
Have a look at this thread:
[url]
http://www.ccsinfo.com/forum/viewtopic.php?t=59721
[/url]
Now you should be able to use the inbuilt functions (depending on the age
of your compiler. So read_program_memory, and write_program_memory.
However the reformatting of the data will remain. Problem is the HEF
is only the low byte of each word in this memory area.
It really is a pain. Honestly thousands of times easier to just add an external
EEPROM.
The code I show there is identical for this chip. Remember the code protection
bit needs to be set to 1, to allow the memory to be written. |
|
|
Tronic19
Joined: 03 May 2022 Posts: 6
|
|
Posted: Wed May 04, 2022 3:30 am |
|
|
Thanks a lot for fast reply:)
I got the last release of the compiler.
Yes, it is painful but i have no choice, my space on pcb is fully optimised (tricky also) and no more space available for adding a classic EEPROM.
(No more pins also ;) )
I will keep you updated here |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9228 Location: Greensville,Ontario
|
|
Posted: Wed May 04, 2022 5:13 am |
|
|
uhoh !..... 'no more pins' !!!!!
best find a bigger PIC real quick, and redesign ASAP..... !!
Over the years I settled on the 46k22 ( the BIG, POWERFUL PIC a few years back...) and only once came close to 'running out of pins' ...had ONE spare.
We've all done it...bought the smallest PIC, made the tinyest PCB then filled the PIC up with code and run out of pins.
Welcome to the 'club'. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Wed May 04, 2022 7:23 am |
|
|
It really does depend massively on what you actually want to do?.
The two problems with HEF, are first that it erases as a 'page', not byte
by byte, and secondly that it only exists as alternate bytes through the
area involved (on PIC 16's). Now the former means that if you have several
values stored, and want to change one, you have to read out the entire
page into RAM, change the value you want to alter in this stored value, then
erase and write the whole lot back. Result a lot of RAM is needed (64 bytes
on your chip). Now most of the chips with HEF, only have a small amount of
RAM, so 'a problem'. Then you have to split everything larger than a byte
and locate it only into alternate bytes of the buffer.
Together these make the HEF handling bulky (both in use of RAM, and
code size).
Now if you are only storing one or two values, you can get away with
a much smaller RAM store than the whole page, and it becomes sort
of usable. So for configuration values that are only written at very long
intervals, and are all changed at the same time it is OK. However for
anything where you need to have several values, and only change
individual ones at a time, 'think again'. If necessary change to another
chip.
It's only 'advantage;, is to the chip manufacturer, where it reduces cost.
For everybody else it is a real pain.
Remember also that when writing the HEF, it is like when you write the
program memory. Everything else has to stop during the write. No
interrupts, no operation from the chip at all. |
|
|
Tronic19
Joined: 03 May 2022 Posts: 6
|
|
Posted: Wed May 04, 2022 8:31 am |
|
|
I need only to backup some data of my product.
(Tiny needs for now, 3 or 4 bytes is OK)
I check your code, but not running.
Value i read all the time is 535 (decimal value)
For your info, i cannot access the usart, i have only access to 3 digit display that display in decimal.
I can put and try to wrote anything, after a reset, i am still at 535 value (decimal) read.
Just few ask:
- Where do you found (which page of the datasheet PDF) the value of 0x1F80 for the HEF_ADRESS ?
- And another ask, i run in 32 Mhz (intosc), is it compliant with your code ?
Thank a lot |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Wed May 04, 2022 10:00 am |
|
|
You have to change the HEF address for whatever chip you use.
You have only spoken about 157x. The HEF address is different for the
different values of 'x' here.
1574/8 0xF80
1575/9 0x1F80
Table 3-1 in the data sheet. |
|
|
Tronic19
Joined: 03 May 2022 Posts: 6
|
|
Posted: Wed May 04, 2022 10:35 am |
|
|
Yep sorry about this, i am using a 16F1578...(SSOP20).
I update the code, and now after trying to program: 0xCF (207 dec), i read (after switch off and switch on again, and making ONLY read sequence) the value of: 513... so still everything wrong... i am not able to read again the value i wrote....
Is there a way to read the flash memory of the pic with MPLAB IPE v5.45 ??
(It is the tool i use with my PICKIT 3 to program the PIC)
(Just to check if program is running on write ?)
Or any suggestion ?
Any help will be really appreciate :( |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Thu May 05, 2022 12:22 am |
|
|
Don't know the MPLAB programming environment, but every programmer I
have used, does allow you to read the program memory. Just read it, save
into a hex file, and then use a hex viewer to compare with the original
hex file. |
|
|
Tronic19
Joined: 03 May 2022 Posts: 6
|
|
Posted: Thu May 05, 2022 1:25 am |
|
|
Ok finally i found a way to check and now i am sure nothing runs :(
Here is the problems i found,
1) i need to remove the #ROM define, because if not , it wrotes always 1,2,3,4 at the adress F80 where i want to store datas.
2) The more tricky is my programmer, when programming, i was in fact erasing data, i need to change the range of write to 0-eff to not go to F80 to erase it, and after to put good range (0-fff) to read it again.
My goal is really to store data, and that i re-read same after a power off.
(Like a classic eeprom)
If someone got another tricks to help, because on 1578 your code don't runs...
I will try to check now with internal functions of CCS ... (the write_program_memory) to see if i can make something runs.... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Thu May 05, 2022 1:47 am |
|
|
The whole point of the #ROM directive, is to prevent the compiler from
writing stuff into that area. It is explained in the code. Compiling without it, you risk the compiler putting other values into the HEF area. It has to
be reserved from use.
You will not only have to reserve the area from programming, you will also
have to make sure that the programmer does not do a full erase, if you
want to save the contents. |
|
|
Tronic19
Joined: 03 May 2022 Posts: 6
|
|
Posted: Thu May 05, 2022 2:15 am |
|
|
I understand but there is HUGE MATTER with that...
My data stored are very important, and i need to kept them always,
even if i upgrate my program with a new flash.
With that directive, it wrotes the datas 1,2,3,4 each time you flash your program... This is crazy... And not logical also... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Thu May 05, 2022 6:21 am |
|
|
No, it won't, if you prevent the programmer from writing to this area,
which you are going to have to do anyway if you want the values to
be preserved. |
|
|
|