Hi,
where I can look the 6.zip example because I have a problem of write a 256bit data in the flash for the offset/gain regulation.
I write this code but dont work
InitFlash:
lda FCDIV
and mFCDIV_DIVLD ;check if DIV bits have been set
bne InitFlash1 ;skip if yes
lda #Div
sta FCDIV ;load divisor value
InitFlash1:
rts
;***********************************************************
;======memorizzazione parametri in FLASH====================
;***********************************************************
MemPar
ldhx #$f080 ; blank pagina FLASH
jsr FlashErase
ldhx #ProcsDat ; indirizzo del primo dato
lda RegSerie ; contenuto del dato
jsr FlashProg1 ; scrittura del dato
aix #1
lda RegSerie+1
jsr FlashProg1
aix #1
lda RegSerie+2
jsr FlashProg1
aix #1
lda RegSerie+3
jsr FlashProg1
aix #1
lda RegFW
jsr FlashProg1
aix #1
lda RegFW
jsr FlashProg1
aix #1
rts
FlashProg1:
psha ;temporarily save entry data
lda #(mFSTAT_FPVIOL+mFSTAT_FACCERR) ;mask
sta FSTAT ;abort any command and clear err
lda #mByteProg ;mask pattern for byte prog comm
bsr DoOnStack ;execute prog code from stack RAM
ais #1 ;deallocate data location from stack
rts ;Z = 0 means there was an error
FlashProg1End:
FlashProg1Size equ FlashProg1End - FlashProg1
FlashErase:
psha ;temporarily save entry data
lda #(mFSTAT_FPVIOL+mFSTAT_FACCERR) ;mask
sta FSTAT ;abort any command and clear errors
lda #mSectorErase ;mask pattern for sector erase
bsr DoOnStack ;execute prog code from stack RAM
ais #1 ;deallocate data location from stack
rts ;Z = 0 means there was an error
FlashEraseEnd:
FlashEraseSize equ FlashEraseEnd - FlashErase
DoOnStack:
pshx
pshh ;save pointer to flash
psha ;save command on stack
ldhx #SpSubEnd ;point at last byte to move to stack
;----------------------------------------------------------------
;Move the routine to the stack
SpMoveLoop:
lda ,x ;read from flash
psha ;move onto stack
aix #-1 ;next byte to move
cphx #SpSub-1 ;past end?
bne SpMoveLoop ;loop till whole sub on stack
;----------------------------------------------------------------
tsx ;point to sub on stack
tpa ;move CCR to A for testing
and #$08 ;check the I mask
bne I_set ;skip if I already set
;----------------------------------------------------------------
sei ;block interrupts while FLASH busy
lda SpSubSize+6,sp ;preload data for command
jsr ,x ;execute the sub on the stack
cli ;ok to clear I mask now
bra I_cont ;continue to stack de-allocation
;================================================================
I_set:
lda SpSubSize+6,sp ;preload data for command
jsr ,x ;execute the sub on the stack
I_cont:
ais #SpSubSize+3 ;deallocate sub body + H:X + command
;H:X flash pointer OK from SpSub
lsla ;A=00 & Z=1 unless PVIOL or ACCERR
rts ;to flash where DoOnStack was called
SpSub:
ldhx SpSubSize+4,sp ;get flash address from stack
sta 0,x ;write to flash; latch addr and data
lda SpSubSize+3,sp ;get flash command
sta FCMD ;write the flash command
lda #mFSTAT_FCBEF ;mask to initiate command
sta FSTAT ;[pwpp] register command
nop ;[p] want min 4~ from w cycle to r
ChkDone:
lda FSTAT ;[prpp] so FCCF is valid
lsla ;FCCF now in MSB
bpl ChkDone ;loop if FCCF = 0
SpSubEnd:
rts
Where is a mistake?
Tanks in advance
fuma