p89c668 iap error

Started by _cjh_, August 11, 2006, 11:45:45 AM

Previous topic - Next topic

_cjh_

hello, all.  first off, embedded systems are my hobby, not profession, so please go easy on me.  if you have some time to spare to help me, i'll be much appreciative.  also, i realize this is a forum to discuss flash magic.  if you feel this post is not applicable to this forum, please help me find a forum that would be.

i'm having difficulties with iap.  i'm using iap to store data in the code block so that i can lose power to the application board but not lose my data (and so that i don't have to have an eeprom chip in the circuit).  i want my code to write (via iap) the current dptr to a location (code mem 30h, 31h - dph, dpl) every time after data is logged to this dptr.  after cycling power, my code reads this code mem location to see if this location is equal to FFh.  if yes, this means there is no data stored yet, and that i should load dptr with the first location for data storage.  [if no, then read the 2 stored locations (code mem 30h, 31h) and load these into dph and dpl - but i never get this far!]

here's what happens after i erase block 1 of the device and program my code... when my application writes the initial dptr constant to code, i get no problems *IF* the application does not write via iap to this dptr storage location (code mem 30h, 31h) ever again.  as soon as there is another command in the code to store the dptr to it's location, iap fails on the second write byte - iap works for code mem 30h, but fails on 31h!  this makes no sense to me because the program counter never even reaches the other command in the code to store the dptr to it's location.

i've written simplified code to test this and i've confirmed this is what happens many times.  i've used the device's data sheet to disable the 2nd dptr, disable external ram access, and disable all interrupts.  i've read the "bible" and review the errata, which did not address this.  

i apologize if i'm being unclear, and i didn't mean for this post to be so long, but i wanted to give what i think is information valuable to the solution.

again, if you have some time to help, i would apprecate it very much.

thanks,

   -chris

p89c668hba, rev g
flash magic: 3.21.116

Andy Ayre

Take a look at our C IAP library. It shows you the assembler needed for the 89C51Rx2Hxx devices, which are almost identical in this respect to the 89C66x devices.

  http://www.esacademy.com/faq/progs/flash.htm

Hope this helps.

Embedded Systems Academy, Inc.
support at esacademy dot com

_cjh_

thank you for the suggestion, andy.  

the only difference my code had with the iap library was that i was using mov #20H to auxr1 instead of using orl in my iap_prog_data_byte routine.  i got my code straight from the device data sheet.  i made the change to orl and got the same results.  

i still don't understand why i can successfully write to code 30h, 31h once, but when i add code to try and write to those same locations any more times, the initial write fails.

maybe i'll try the 8052.com forum.

thanks again,

   -chris