Saving data to memory permanently

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Saving data to memory permanently

2,239 Views
gaminn
Contributor IV
Hi,
I would like to save an output during executing my program on QY4 permanently to memory, so when I switch of and on my device, it will be remember it. Is it somehow possible?
 
Martin
Labels (1)
0 Kudos
Reply
3 Replies

970 Views
Ake
Contributor III
Hi,
Yes it can easily be done.
If you have some data that you want to save, copy the row of Flash EPROM where you intend to save the data, read the row from Flash and store it in RAM. Modify the byte in RAM you intend to change. Point at the array and call the write routine in the ROM in the HC908QY. Best is if you check that the byte is not written before ( = 0xff) , and if it has been erase it first.
For a  better explanation, check the AN2635 at:
 
Note that the Flash EPROM row where you intend to save the data, cannot be protected by the FLBPR register, as it is in Flash EPROM  itself.
It is possible if the FLBPR is not used before ( = 0xff) of course to write the data into the Flash EPROM and then change the FLBPR to protect the changed data.
 
Hope that helps!
 
Regards,
Ake
 
 
 
0 Kudos
Reply

970 Views
gaminn
Contributor IV
Thanks for excellent explanation, I wil try it.
 
Martin
0 Kudos
Reply

970 Views
bigmac
Specialist III
Hello Martin,
 
Further to what Ake has suggested, it is best to choose the first flash page for the storage of non-volatile data (assuming a single page provides sufficient storage).  The program code would then commence at the second flash page.  This means that the FLBPR register can be programmed to protect the program code, but leave the non-volatile data page unprotected.
 
I have previously used the following (absolute) assembly code, for a QY4 device, to erase the first flash page, and then program a word value to the first two positions in the page.
 
FLASH     EQU    $EE00  ; 4096 bytes total to $FDFF
PBLOCK    EQU    FLASH  ; Non-volatile block for data
DATSIZE   EQU    2
CODE      EQU    FLASH+$40 ; Start of program code
FLBPRVAL  EQU    {(FLASH-$C000)/$40+1} ; Unprotect first block
SPDVAL    EQU    13     ; ~(3.2 * 4)
 
; ISP ROUTINES:
ERARNGE   EQU    $2806  ; Erase range of flash
PRGRNGE   EQU    $2809  ; Program range of flash
 
; RAM REGISTERS
; ISP DATA STRUCTURE:
  ORG     RAM+8
CTRLBYT   DS     1      ; BIT-6 = Mass erase flag
CPUSPD    DS     1      ; VALUE = 4*Fop (MHz)
LADDR     DS     2      ; Last address of range (word value)
WADDR     DS     2      ; Wireless address value

 
  ORG     CODE          ; Start of program code
 
;***************************************************************
; ERASE FLASH PAGE & WRITE BLOCK
; On exit, CF = 1 if programmed data is verified, otherwise CF = 0
 
WRBLOCK:  MOV    #SPDVAL,CPUSPD
          CLR    CTRLBYT        ; Page erase only
          LDHX   #PBLOCK
          LDA    #DATSIZE
          PSHX
          ADD    1,SP           ; Add LS address
          DECA                  ; Last position in block
          TAX
          STHX   LADDR
          PULX
          JSR    ERARNGE        ; Erase range - disable interrupts
          LDHX   #PBLOCK
          JSR    PRGRNGE        ; Program block
          CLI                   ; Re-enable interrupts
          RTS
 
;***************************************************************
 
  ORG     FLBPR                 ; Flash block protect register
          DC.B   FLBPRVAL       ; First flash block unprotected
 
Regards,
Mac
 
0 Kudos
Reply