Hi all, I'm having trouble getting a routine to write data where I think it should. I've not done any Flash writing for a long time so probably missing something pretty obvious. I've checked the d/s and had a look around for examples and can't spot anything The routine receives a packet of 48 bytes and writes it to an address defined by the value of a two-digit LED display. For example, if the display is showing 09, then the 48 bytes should be written to the block starting at (9*64) + 0x1800, where 0x1800 is the base address What I'm getting though is a write only when display =3D 00 and only to the block address in the set-up declaration, eg t_data =3D 0x1800 If I change t_data to 0x1840, it will write there. And explicitly setting TBLPTR in the code doesn't make a difference. The blk_add routine returns the correct value for TBLPTR, the code seems to ignore it If 0x1840 is the intended target (dg =3D 1, t_data =3D 0x1800), the write will happen only if I clear it with 0000 data statements in the program, otherwise the locations will stay as FFFF. But that write does miss the first byte. All 48 bytes are correct when dg=3D00 Below is the section of code Can anyone see what's missing ? I'm sure there's a common cause for what's happening TIA Joe ------------------ mov macro val,file movlw val movwf file endm t_data =3D 0x1800 ;multiply digits by 64 to find block, add t_data base ; ;eg ;digits =3D 23 in =3D 05c0, + 1800 =3D 1dc0 ;Erase block ;Write buffer48 to block wr_block movff buffer,postinc0 ;last byte received ; movlw .0 ;display value, manual test ; movwf dg01 ; movlw .0 ; movwf dg10 call blk_add ;get block start address ; clrf tblptru ;Flash block address, manual test ; movlw 0x18 ; movwf tblptrh ; movlw 0x40 ; movwf tblptrl ;Block command can resolve to 8 bytes ;Erase command can resolve to 64 bytes (x00,x40,x80,xc0 starts) ;Erase block erase bcf eecon1,cfgs ;erase block bsf eecon1,eepgd bsf eecon1,wren bsf eecon1,free bcf intcon,gie mov 0x55,eecon2 mov 0xaa,eecon2 bsf eecon1,wr nop tblrd*- ;write RAM to Flash as 64-byte (8*8) block mov .8,bitcnth ;'8-bytes' counter lfsr fsr1,buffer48 ;data to write write mov .8,bitcntl ;byte counter copy8 movff postinc1,tablat ;copy 8 bytes to write buffer tblwt*+ decfsz bitcntl ;byte counter bra copy8 mov 0x55,eecon2 mov 0xaa,eecon2 bsf eecon1,wr nop decfsz bitcnth ;8-byte counter bra write bcf eecon1,wren goto wait ;done ;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ;Get Flash address from dg10:dg01, tens:units, 00d-30d blk_add rlncf dg10,w ;combine dg10:dg01 rlncf wreg rlncf wreg ;(dg10 * 8) + (dg10 * 2) addwf dg10,w addwf dg10,w addwf dg01,w ;+ dg01 movwf temp1 ;temp1 =3D (dg10 * 10) + dg01 clrf temp0 clrc ;* 64 rrcf temp1 rrcf temp0 rrcf temp1 rrcf temp0 clrc ;add 0x1800 base address movlw low(t_data) addwf temp0 movlw high(t_data) addwfc temp1 clrf tblptru ;Flash block address movff temp1,tblptrh movff temp0,tblptrl return ----- No virus found in this message. Checked by AVG - www.avg.com Version: 2016.0.7797 / Virus Database: 4656/13173 - Release Date: 10/08/16 --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .