RetroBSD

2.11BSD operating system for microcontrollers
It is currently Wed Apr 26, 2017 10:06 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Thu Nov 03, 2016 8:14 am 

Joined: Mon Aug 08, 2016 9:44 am
Posts: 2
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.


Top
 Profile  
 
PostPosted: Thu Nov 03, 2016 10:50 am 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1785
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
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

_________________
Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
PostPosted: Thu Nov 03, 2016 3:28 pm 
Contributor

Joined: Mon Nov 12, 2012 1:34 pm
Posts: 1076
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron




Powered by phpBB® Forum Software © phpBB Group

BSD Daemon used with permission