View previous topic :: View next topic |
Author |
Message |
garyzheng
Joined: 22 Jul 2004 Posts: 25
|
Write_Program_Memory command:) |
Posted: Wed Aug 04, 2004 9:33 am |
|
|
Now i am pursueing a project for RF link. There is a large amount of data to store, and there is no external EEprom on my board. So i want to store those data into the program memory of PIC16F873.
I try to use the built-in function Write_program_memory(),but it can not work. So could someone give out some sample code for write_program_memory() function which can work. thank you! |
|
![](templates/subSilver/images/spacer.gif) |
bdavis
Joined: 31 May 2004 Posts: 86 Location: Colorado Springs, CO
|
|
Posted: Wed Aug 04, 2004 11:41 am |
|
|
Did you try disabling all interrupts? I heard this was an issue - if interrupts are enabled, then it won't work. I saw a post on this not too long ago. |
|
![](templates/subSilver/images/spacer.gif) |
garyzheng
Joined: 22 Jul 2004 Posts: 25
|
thank you, but i still have some question :) |
Posted: Wed Aug 04, 2004 2:05 pm |
|
|
1) If i want to write the data into program memory, that means i had to enable the "Flash memery Writable" in configuration bits. --is it (the #fuse NoProtect ) flag that enable the "flash memory write"?
2)low voltage programming---did i need to enable the low voltage programming during the data writing procession into program memory? because when we use ICD2 to burn the program into chip, the program voltage is 9V, but the common usage for PIC MCU is only 5V.
3) So when i use the function write_program_memory, what is the #fuse flag?
//****************************
char rx_buffer[32];
int *pointer;
pointer = rx_buffer;
while(index<11)
{
write_program_memory(0x0e00+index,pointer[index],2);
index++;
}
//*****************************
part of my code, for writing the data from rx_buffer (RS232) into program memory.
anyone could told me whether there is something wrong with it:)
4) The difference between write_program_eeprom and write_program_memory. From the CCS manual, it looks can achieve the same function, write the data into program memory, but whether there is some difference?
Thank you!! |
|
![](templates/subSilver/images/spacer.gif) |
bdavis
Joined: 31 May 2004 Posts: 86 Location: Colorado Springs, CO
|
|
Posted: Wed Aug 04, 2004 4:26 pm |
|
|
Sorry - I can't help you on that one - I haven't directly tried it, but may try it in a few days. You may want to look at the bootloader.c and other bootloaders, and look at their fuse settings since they need to program the memory. Of course it can't be protected, but I believe the PROTECT fuse pertains to externally being able to read the program memory. |
|
![](templates/subSilver/images/spacer.gif) |
jpa Guest
|
Re: thank you, but i still have some question :) |
Posted: Thu Aug 05, 2004 5:47 am |
|
|
garyzheng wrote: | 1) If i want to write the data into program memory, that means i had to enable the "Flash memery Writable" in configuration bits. --is it (the #fuse NoProtect ) flag that enable the "flash memory write"?
2)low voltage programming---did i need to enable the low voltage programming during the data writing procession into program memory? because when we use ICD2 to burn the program into chip, the program voltage is 9V, but the common usage for PIC MCU is only 5V.
3) So when i use the function write_program_memory, what is the #fuse flag?
//****************************
char rx_buffer[32];
int *pointer;
pointer = rx_buffer;
while(index<11)
{
write_program_memory(0x0e00+index,pointer[index],2);
index++;
}
//*****************************
part of my code, for writing the data from rx_buffer (RS232) into program memory.
anyone could told me whether there is something wrong with it:)
4) The difference between write_program_eeprom and write_program_memory. From the CCS manual, it looks can achieve the same function, write the data into program memory, but whether there is some difference?
Thank you!! |
1) I didn't try yet, so I can't help you on this; reading Microchip datasheet should give you the answer
2) I don't think it is necessary but didn't try it yet
3) Second argument to Write_program_memory is a pointer to data byte; however pointer[index] is not a pointer... the second argument could be "pointer+index"or &(pointer[index])
4) Difference between functions is the 3rd argument of write_program_memory which indicates the number of bytes to be written. write_program_eeprom writes only two bytes.
Hope it can help you. |
|
![](templates/subSilver/images/spacer.gif) |
garyzheng
Joined: 22 Jul 2004 Posts: 25
|
thank you for tips |
Posted: Thu Aug 05, 2004 8:35 am |
|
|
i will try and look what will happen. But if some one had example code, give me some hints or post some part of code here:) |
|
![](templates/subSilver/images/spacer.gif) |
garyzheng
Joined: 22 Jul 2004 Posts: 25
|
OK, i think i achieve the goal! |
Posted: Thu Aug 05, 2004 9:32 am |
|
|
So hehe, after reading some assemble code, i found that we should disable all the interrupts before write the ROM. Thank you for some hints! |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Aug 05, 2004 11:18 am |
|
|
Quote: |
Did you try disabling all interrupts? I heard this was an issue - if interrupts are enabled, then it won't work. I saw a post on this not too long ago.
|
The first response to you post told you that! |
|
![](templates/subSilver/images/spacer.gif) |
garyzheng
Joined: 22 Jul 2004 Posts: 25
|
thanks, mark, but i think i meet another problem! |
Posted: Fri Aug 06, 2004 8:25 am |
|
|
when I write the data sentence by sentence into ROM, it can work. But when i write the data like a stream, it can only wirte the first sentence, after that , it can not work?
because the data is transmitted by RS232(BAUD RATE= 9600) from PC
I wonder whether the Writing procession into ROM should consume some time, but the data stream transmission from RS232 is too faster than the writing procession of ROM, so that cause the error:)
so someone meet that problem before, and could some one told me how many time the Write_program_memory will take:)
thank you! |
|
![](templates/subSilver/images/spacer.gif) |
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Fri Aug 06, 2004 8:40 am |
|
|
Why not write a test program that writes to program memory without the serial link. Break the problem down. If you can write a series of constants to program memory you can be sure the problem is or is not the function to write to program memory. You can read the HEX file from the chip after it runs and see if it is working. |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Aug 06, 2004 10:45 am |
|
|
Yes writing to the flash takes some time. Look at the datasheet for the time required. |
|
![](templates/subSilver/images/spacer.gif) |
garyzheng
Joined: 22 Jul 2004 Posts: 25
|
thanks, mark and neutone:) |
Posted: Fri Aug 06, 2004 11:59 am |
|
|
i will try to delay the package transmission from PC |
|
![](templates/subSilver/images/spacer.gif) |
garyzheng
Joined: 22 Jul 2004 Posts: 25
|
new problem:) |
Posted: Mon Aug 09, 2004 1:10 pm |
|
|
Now my program can work by receiving and store the data into program memory package by package. But now I found a weird problem.
**************part of my program*************
if( (rx_preamble[0]=='S') && (rx_preamble[2]=='1')) // screen 1
{
if( (rx_preamble[5]=='A') && (rx_preamble[7]=='1'))
{
storecount=11;
startadd=0x0d00;
store16(storecount,startadd);
return;
}
if ( (rx_preamble[5]=='A') && (rx_preamble[7]=='2'))
{
storecount=11;
startadd=0x0d10;
store16(storecount,startadd);
return;
}
if ( (rx_preamble[5]=='A') && (rx_preamble[7]=='3'))
{
storecount=5;
startadd=0x0d20;
store16(storecount,startadd);
return;
}
if ( (rx_preamble[5]=='A') && (rx_preamble[7]=='4'))
{
storecount=15;
startadd=0x0d30;
store16(storecount,startadd);
return;
}
if ( (rx_preamble[5]=='B') && (rx_preamble[7]=='1'))
{
storecount=11;
startadd=0x0d40;
store16(storecount,startadd);
return;
}
if ( (rx_preamble[5]=='B') && (rx_preamble[7]=='2'))
{
storecount=10;
startadd=0x0d50;
store16(storecount,startadd);
return;
}
if ( (rx_preamble[5]=='B') && (rx_preamble[7]=='3'))
{
storecount=10;
startadd=0x0d60;
store16(storecount,startadd);
return;
}
if ( (rx_preamble[5]=='B') && (rx_preamble[7]=='4'))
{
storecount=10;
startadd=0x0d70;
store16(storecount,startadd);
return;
}
else
{
return;
;
}
}
**********************************************
I store several different infomation into program memory from address 0x0d00 to 0x0df0. Every time I store one of the infomation(such as I store the info into address 0x0db0), the infomation stored in the lower address(such as 0x0dc0,0x0dd0,0x0de0) will change. Some strange character will shift from the upper address.
some one met this problem before, give me some idea:)
another question is for the write procession time. I know that the flash memory writing time is about 4ms to 8ms for one word. During the writing procession , MCU should shut down the interrupts. my method is to give out 100ms delay before enable the global interrupts. But sometimes it can work, but sometimes, i can not work.
can some one give out some good ideas, thank you:) |
|
![](templates/subSilver/images/spacer.gif) |
garyzheng
Joined: 22 Jul 2004 Posts: 25
|
some one met this problem before?:)please give me a hint:) |
Posted: Tue Aug 10, 2004 8:28 am |
|
|
thank you! |
|
![](templates/subSilver/images/spacer.gif) |
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Tue Aug 10, 2004 9:09 am |
|
|
Are you by chance attempting to write across page boundries? You may only write one page at a time and your packet size should be based on the page size. |
|
![](templates/subSilver/images/spacer.gif) |
|