View previous topic :: View next topic |
Author |
Message |
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
Trouble understanding write_program_memory() function |
Posted: Thu Mar 12, 2015 7:47 am |
|
|
Hi,
I am trying to develop a bootloader for my project. I am unable to understand how the write_program_memory function works. I have read the help file and the loader.c but I cannot understand how to write a word to the program memory.
For example I would like to write the following words
EF52 F000 EF05 F000
But instead of the above words I get mostly zeroes (using the MPLAB sim)
Please help...
thanks
a |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1349
|
|
Posted: Thu Mar 12, 2015 7:57 am |
|
|
You need to provide:
Chip#
Compiler Rev#
Small compilable code that can be copy/pasted by others to test out.
A lot of it is going to depend on what chip in particular and how you are using write_program_memory(). The general gist is if you meet all the chip specific requirements, then it will write that data to memory and possibly erase the page (depending on the address you supply).
The info you have given thus far is insufficient for a solid answer without us guessing and hoping to get it right. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Thu Mar 12, 2015 9:09 am |
|
|
As a comment though, I can't think of any PIC that would accept those words in it's program memory.....
PIC16 - 14bits wide
PIC24 - 24bits wide
Remember that in each case these words are sent as byte or 16bit word 'pieces', so every fourth byte of the PIC24 memory is 'N/A', while the top two bits of every alternate byte of the PIC16 memory is similarly N/A. etc..
Also remember that writing to the first byte of a page, erases the whole page.
Last edited by Ttelmah on Thu Mar 12, 2015 12:48 pm; edited 1 time in total |
|
|
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
RE: |
Posted: Thu Mar 12, 2015 9:53 am |
|
|
sorry I forgot to mention...
I am using 18F4550 mcu, with PCH compiler 4.073
thanks
a |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Thu Mar 12, 2015 12:47 pm |
|
|
Your compiler version is very early for V4. It was one that definitely still had problems, and things like the program memory function, may well have problems.....
What address are you trying to write to?.
It needs to start on a 64byte boundary. Say 0x7FC0.
You need a 32byte array, and load this with the data. Then write the array.
You can then do a second 32byte write to the second half of the block.
Understand that an erased bit, is '1'. When you write a bit you can set it to '0'. If you write over a byte that is not erased, more and more bits will go to '0'. So if you had 0x30, and wrote 0xCF, the result would be 0. If you are trying to write to anywhere but the start of a block, this will be what you see.... |
|
|
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
re |
Posted: Fri Mar 13, 2015 1:07 am |
|
|
thanks for the help.
I managed to solve the problem, I used an int array in the function, as you had mentioned a 32 bit array is required for this.
Now however I have to figure out how the loader.c program works......
thanks
a |
|
|
|