PIC16f15355 SAF

Thread Starter

Missio2468

Joined Mar 18, 2022
74
I am programming in PIC16f15354 and need to store values in Storage area flash as it does not have eeprom. To read/write in SAF storage I looked at the datasheet but there is a problem . Different method is shown is write flow chart and different in steps mentioned. This is getting me confused. Thanks for helping in advance.
I have mentioned PIC16f15355 in title but using PIC16f15354
 

upand_at_them

Joined May 15, 2010
939
What page in the datasheet? I'm looking in the datasheet and don't see a flowchart. What page are the steps listed?...I don't see that either. The SAF is enabled by clearing the SAFEN bit in the Config Word. It should then be treated like R/W program memory.
 

Thread Starter

Missio2468

Joined Mar 18, 2022
74
Steps are included in Page 160 and Flowchart is shown in figure 13-5 page 162
Also I have enabled the Safen Bit but for write, method is different
 

geekoftheweek

Joined Oct 6, 2013
1,429
Just a super basic sort of code to go by... You will have to fill data_to_write with the data you want to write, and perform a row erase before writing.

Code:
data_to_write[64] = { the data to write };

NVMADRH = address_to_write_to  >> 8;
NVMADRL = address_to_write_to;
NVMCON1.NVMREGS = 0;
NVMCON1.WREN = 1;
NVMCON1.LWLO = 1;

for (i =0; i < 62; i+=2) {
  NVMDATL = data_to_write[i];
  NVMDATH = data_to_write[i+1];
  INTCON.GIE =0;
  NVMCON2 = 0x55;
  NVMCON2 = 0xAA;
  NVMCON1.WR = 1;
  INTCON.GIE =1;
  NVMADR ++;
}

NVMDATL = data_to_write[62];
NVMDATH = data_to_write[63];
NVMCON1.LWLO =0;
INTCON.GIE =0;
NVMCON2 = 0x55;
NVMCON2 = 0xAA;
NVMCON1.WR = 1;
INTCON.GIE =1;
NVMCON1.WREN =0;

INTCON.GIE =0;
NVMCON2 = 0x55;
NVMCON2 = 0xAA;
NVMCON1.WR = 1;
INTCON.GIE =1;
This is more or less the example code 13-4 expanded out a bit and sort of "C" like. I normally use ASM so the exact bit names are probably not right by C names, but you'll get the idea.
 
Last edited:

geekoftheweek

Joined Oct 6, 2013
1,429
OK , I will try and this and update it if it works
Good luck!! Some of the newer parts have some bigger hurdles to jump when working with flash memory that can make things a bit tough. I've found though the example code always works, but takes a bit of time to trace through it several times to find the variables you need to sort out to make it right.
 
Top