Author Topic: Problems with PIC18f26k22, XC8 and EEPROM.  (Read 617 times)

0 Members and 1 Guest are viewing this topic.

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 2113
  • Country: it
Problems with PIC18f26k22, XC8 and EEPROM.
« on: December 06, 2016, 01:37:26 am »
Cross posting from the microchip forum.
XC8 1.38.
So, i want to save data to eeprom and it doesn't get saved.
I am using the exact code in the datasheet (which works in other projects by the way)
function prototype:

Code: [Select]
void write_eeprom(unsigned int address, unsigned char data)
address and data are correctly passed, but any write to the registers have no effect. like the instruction wasn't excecuted at all (for example, if i stop the debugger and write "10" to EEADR, if i go inside write_eeprom having address = 5 after the instruction EEADR = address EEADR is still 10)

a couple of notes:
there is no issue with writing and int on a char, i do it all the time.
the routine is the one written by microchip, asm or c doesn't make a difference. it's working in other projects, with the same micro. thinking about creating a new project and import the sources.
single stepping the disassembly skips the instructions where i assign data to EEADR but i think that's more a debugger problem


... After some time ...
No it wasn't. Turns out that the routine is working but if i run it 22 times an eeprom error will be generated during write and the pic will reset.
Not an addressing problem, as if i start writing from location "0" it will reset at writing "21". if i start from location "10" it will reset at "31".
It happens with multiple pics
« Last Edit: December 06, 2016, 02:33:24 am by JPortici »
 

Offline RogerRowland

  • Regular Contributor
  • *
  • Posts: 193
  • Country: gb
    • Personal web site
Re: Problems with PIC18f26k22, XC8 and EEPROM.
« Reply #1 on: December 06, 2016, 02:50:53 am »
You don't have the watchdog timer running do you?
 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 2113
  • Country: it
Re: Problems with PIC18f26k22, XC8 and EEPROM.
« Reply #2 on: December 06, 2016, 04:52:10 am »
Yes, it was. i figured that out

even though i was sure that the watchdog was disabled during debug
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf