• AVR Freaks

AnsweredHot!PIC18F46K22 EEPROM reading/writing specification

Author
tealbrains
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2020/08/11 00:15:31
  • Location: 0
  • Status: offline
2020/08/13 04:50:16 (permalink)
0

PIC18F46K22 EEPROM reading/writing specification

Hi all,
 
I have made a custom programmer for firmware upgrades on the field by retrofitting PIC18F46K22 based boards with a more modern micro that can read a stored .hex and controls the PGD PGC MCLR lines with an LVP approach. These were the pins available from production.
 
So far I have been able to reflash the PIC (code memory). The next step (which I hoped would be straight forward) was to read the EEPROM and write it back as the "Chip Erase" procedure wipes everything, including the EEPROM.
 
I have followed everything the Programming Specification document says, page 26 : http://ww1.microchip.com/downloads/en/DeviceDoc/41398B.pdf
I believe my understanding and implementation should be correct as I have managed to flash the chip, but I am obviously missing something or there is an issue that is not documented for the EEPROM.
 
I have tried variations of the commands, such as not doing the NOP, introducing delays, sending first the AddrH, etc. No luck.
 
I still don't understand why the "shift out data" in step4 is described like this:
0010 MSB LSB
Figure 4-4 does not quite match that description. It looks like a copy paste from Figure 4-1.
 
Isn't every read supposed to be [COMMAND]  [8 DUMMY CLOCKS] [READ 8 BITS] ?
I have tried:
[0010] [0000 0000] [READ BYTE]
[0010] [READ BYTE] [READ BYTE]
 
Neither worked.
 
Has anybody encountered issues around reading/writing to the EEPROM over the PGD/PGC pins? MPLab + Pickit4 does it so there must be a way. Any help is welcome.
 
Thanks
#1
tealbrains
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2020/08/11 00:15:31
  • Location: 0
  • Status: offline
Re: PIC18F46K22 EEPROM reading/writing specification 2020/08/13 17:18:31 (permalink)
+2 (2)
Replying to my own post.
 
I got it working. The documentation is misleading. I confirmed the operation by putting a logic analyzer on the PGD PGC lines and doing an EEPROM dump from MPLAB. I could see how it was done and implemented it.
 
[0010] [0000 0000] [READ BYTE] -> This is the right approach. You can ignore the MSB - LSB stuff mentioned on the Programming Specification document. Another reason why it was not working for me is because I was flashing a .hex that had the CPD bit set. This was from a former attempt to see if EEPROM would be preserved from a Chip Erase (as the document would indicate), but what it really does is it prevents recovering the EEPROM content externally. Everything comes back as 0x00.
 
Sometimes posting the problem just helps.
 
Cheers
#2
NorthGuy
Super Member
  • Total Posts : 6291
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: online
Re: PIC18F46K22 EEPROM reading/writing specification 2020/08/13 19:20:01 (permalink)
+2 (2)
You don't have to erase EEPROM when you do the bulk erase. When you erase, you specify the code which selects the blocks to be erased. 0x83 will preserve EEPROM. You write 0x8383 to 0x3c0004 to accomplish this.
 
If you don't erase EEPROM, you don't need to read it and write back.
#3
tealbrains
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2020/08/11 00:15:31
  • Location: 0
  • Status: offline
Re: PIC18F46K22 EEPROM reading/writing specification 2020/08/13 19:52:42 (permalink)
0
Hi NorthGuy,
 
That's what I initially thought should be possible. I have not found a reference to 0x83 on the manual. Perhaps for another PIC family?
 
Cheers
#4
NorthGuy
Super Member
  • Total Posts : 6291
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: online
Re: PIC18F46K22 EEPROM reading/writing specification 2020/08/13 19:57:24 (permalink) ☼ Best Answerby tealbrains 2020/08/13 20:16:09
+2 (2)
tealbrains
That's what I initially thought should be possible. I have not found a reference to 0x83 on the manual. Perhaps for another PIC family?

 
If you look at the values in the Programming Specification, the number is a bit mask. Even though 0x83 is not listed, it's easy to figure out what it does, and it works as expected.
 
#5
tealbrains
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2020/08/11 00:15:31
  • Location: 0
  • Status: offline
Re: PIC18F46K22 EEPROM reading/writing specification 2020/08/13 20:12:39 (permalink)
0
Hi NorthGuy,
 
Ok, that makes sense. I might give that a go just for kicks. You will agree with me that it could have just been written plainly using a traditional 16 bit table with a description for each bit as found on pretty much any datasheet.
 
What gives it away is the Chip Erase which is just all the bits set around 0x0080... Otherwise they could have just been commands encoded in a 16 bit variable and only executed if they match "switch" cases in a parser approach instead of a loop + "if(option&command)" which is probably what is done internally here.
 
Thanks again for sharing your knowledge on the topic. Hopefully this thread will help other users!
 
 
#6
tealbrains
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2020/08/11 00:15:31
  • Location: 0
  • Status: offline
Re: PIC18F46K22 EEPROM reading/writing specification 2020/08/14 04:18:58 (permalink)
+1 (1)
Just to close the loop:
 
I tried keeping the EEPROM intact and it worked issuing 0x8F83. 0x8383 would also likely work, the B in 0xABAA determines EEPROM Code Block. I am not exactly sure of what that represents.
 
It works as it is, good enough for this retrofit. Gotta move on.
#7
Jump to:
© 2020 APG vNext Commercial Version 4.5