It was an easy mistake to make, CONFIG1L<0> == 0 to enable is a bit counter intuitive, and I've logged a ticket.
So now I have a bunch of product in the wild that I'd really like to turn BOR on for. We have a bootloader which (mercifully) leaves the top 512Bytes of flash clear so I just need to:
Read the config1l from flash and check if the bit is set.......working
Erase the top 512bytes of flash (this is the smallest erase block for this device)......working
Write the config registers back.....not working
I mean, what could possibly go wrong right?
My routine to write a word is based on
7.5.2 FLASH PROGRAM MEMORY WRITE
SEQUENCE (WORD PROGRAMMING)
from the data sheet
And it looks like this:
Code: Select all
void writeWord(unsigned long addr, unsigned char lsb, unsigned char msb)
{
GIE_bit=0;
TBLPTRU=(addr & 0xFF0000)>>16;
TBLPTRH=(addr & 0xFF00)>>8;
TBLPTRL=addr & 0xFF;
TABLAT=lsb; //config1L
asm TBLWT*+
TABLAT=msb; //config1H
asm TBLWT*
asm {
MOVLB 0x0F
BSF EECON1, WWPROG
BSF EECON1, WREN
MOVLW 0x55
MOVWF EECON2
MOVLW 0xAA
MOVWF EECON2
BSF EECON1, WR
BSF INTCON, GIE
BCF EECON1, WWPROG
BCF EECON1, WREN
}
GIE_bit=1;
}
Code: Select all
writeWord(0x1FFFF0,0xA0,0xF6); //Config 1
writeWord(0x1FFFF2,0xAA,0xFF); //Config 2
writeWord(0x1FFFF4,0x02,0xF0); //Config 3
writeWord(0x1FFFF6,0xFF,0xF7); //Config 4
writeWord(0x1FFFF8,0x03,0xFE); //Config 5
writeWord(0x1FFFFA,0xFF,0xFE); //Config 6
writeWord(0x1FFFFC,0x1D,0xF0); //Config 7
writeWord(0x1FFFFE,0xF8,0xF3); //Config 8
I'm missing something stupid I know.....
Anyone got any pointers?
PK