RetroBSD
http://retrobsd.org/

Can't Writing data on Flash memory of the PIC18F47J53
http://retrobsd.org/viewtopic.php?f=3&t=37804
Page 1 of 1

Author:  Chuoiujk [ Thu Nov 03, 2016 8:14 am ]
Post subject:  Can't Writing data on Flash memory of the PIC18F47J53

Hi!
I am using the 18F47J53 in Hitech PICC18-PRO compiler with MPLAB-X IDE, and for some reason there happens to be absolutely no support for the reading/writing function to either the flash or the EEPROM. All I need to do is write a received mobile telephone number that is read from a GSM module when receiving an SMS. Then later recall this number for comparison.
PIC18F47J53 datasheet :http://www.kynix.com/uploadfiles/pdf8798/PIC18F47J53T-I2fML_10344.pdf
It seems as though it should be a really simple procedure using on of the predefined commands such as "eeprom_write(unsigned int address,unsigned char data);", though after checking why I get an error, I see that these commands are not supported, and even the basic standard command "EEPROM_WRITE(addr, data)" which does compile, does not do anything as it was "Added only for code portability", and the functions have been commented out.

Does this mean that this processor does not support any sort of internal read/write functionality, or has it just never been defined.

I have started manually (bit-wise) writing read/write/erase functions for this though without proper addressing could cause some major run time errors, especially due to the fact that the erase function can only work in blocks of 1024 bytes.

The write function looks something like this:

while(WR != 0){;} // wait till EEPROM idle

/* Load Table pointer Reg with Write to address (previously block erased) */
TBLPTRU = Code_Addr_Upper; // Load TBLPTR with Base Addresses?
TBLPTRH = Code_Addr_High; // Load TBLPTR with Base Addresses?
TBLPTRL = Code_Addr_Low; // Must be EVEN Addresses?

do{
GIE = 0; /* disable interrupts */
}while(GIE != 0); /* make sure it worked */

WREN=1; /* enable writes */
EECON2=0x55; // required sequence for EEPROM update
EECON2=0xAA;

do{
WR = 1; /* disable interrupts */
}while(WR != 1); /* make sure it worked */

WREN=0; /* Disable writes */
GIE=1; // re-enable interrupts
which receives 2 bytes at a time as the datasheet states that the smallest write size is 1 word at a time.

Has anyone found a way around this? Surely there is a simpler way.

Any help would be greatly appreciated.

Author:  majenko [ Thu Nov 03, 2016 10:50 am ]
Post subject:  Re: Can't Writing data on Flash memory of the PIC18F47J53

Not really on topic... you can't run RetroBSD on a PIC18...

However, this is code I use successfully on the PIC18F25K20 which is very similar. It's for the XC8 compiler, but the theory of operation should be the same:

https://github.com/UECIDE-Cores/pic18/b ... M/EEPROM.c

Author:  wiz [ Thu Nov 03, 2016 3:28 pm ]
Post subject:  Re: Can't Writing data on Flash memory of the PIC18F47J53

Hi,

I would suggest you look at the actual assembly code trying to do the writing.

Much easier to figure out what is actually happening and in what order.

Making an assembly routine to do the actual write is a pretty simple way to make sure it always works. Then linking that into your higher level language stuff.

Lots of fun.

Wiz

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/