View previous topic :: View next topic |
Author |
Message |
tanyamahen
Joined: 01 Jul 2004 Posts: 14
|
please someone help me with external memory write |
Posted: Sat Aug 14, 2004 11:38 pm |
|
|
Hi
I have pic18f8520 all data bus conected to a flash... memory is maped to 0x0fffff - 0x1fffff ....
My question is how to write a data to flash and read from it...
I did the following....
int imagedata[128]
int readdata;
setup_external_memory(2)
write_external_memory( 0x0fffff, imagedata,2);
delay_ms(4);
read_external_memory( 0x0fffff, readdata,2);
will this work...
I don't have the hardware to test... I will receive the hardware in 3 weeks time... so I need to finish the coding before the hardware arrive.. then only I have test....
Am I in correct path... Can any one help me on this please...
regards
Tanya |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Aug 15, 2004 3:28 pm |
|
|
What flash memory chip are you using ?
CCS has a driver for external flash memory. It's called AT29C1024.C
and it's in this folder: c:\Program Files\Picc\Drivers
This driver uses these functions:
write_external_memory()
read_external_memory()
If you have the CCS compiler, then you should study this file. |
|
|
tanyamahen
Joined: 01 Jul 2004 Posts: 14
|
External Memory |
Posted: Mon Aug 16, 2004 1:39 am |
|
|
Hi
I am using 28f640j3..
I really got confuse about the setup_external_memory() function...
Because in the device header file says...
// Constants used in SETUP_EXTERNAL_MEMORY() are:
#define EXTMEM_BYTE_WRITE 0x80
#define EXTMEM_BYTE_SELECT 0x81
#define EXTMEM_WORD_WRITE 0x82
#define EXTMEM_DISABLE 0
// Use one of the above and optionaly OR in one of:
#define EXTMEM_WAIT_0 0x30
#define EXTMEM_WAIT_1 0x20
#define EXTMEM_WAIT_2 0x10
#define EXTMEM_WAIT_3 0x00 // Default
This function is setting the MEMCON Register...
If I want use the external bus I need set "EBDIS" = 0 in the MEMCON Register. But if I use above "EXTMEM_BYTE_SELECT 0x81" then EBDIS bit get set to 1 ?? That mean no external bus only I/O ports...
Any idea?..
Thanks for helping me.... I am going to have look at the example file you were telling me about...
Thanks
Tanya |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Aug 17, 2004 12:50 pm |
|
|
I guess that you want to run code in external memory.
If you look at the Readme.txt file in this folder, c:\Program Files\Picc
you will see a short explanation of how to do this. CCS says to
use the #build(memory= xxxx:xxxx) statement to define the external
memory range. Presumably, the compiler will then put code in the
external address range. You would then use #org statements to
define the location of individual functions.
I made a small test program to try this. I don't have a demo board
to test this, but it seems to work. The .LST file shows there is an
initial GOTO statement at address 0000, which jumps to main() which
is located in external memory.
Since I don't have a demo board, this is about the only help I can
give you on this. You will have to test it for yourself, in hardware.
Code: | #include <18F8520.h>
#fuses XT, NOWDT, PUT, PROTECT, NOLVP
#use delay(clock = 4000000)
//#use rs232(baud = 9600, xmit=PIN_C6, rcv=PIN_C7)
#build(memory=0x10000:0x1FFFF)
#org 0x11000,0x110FF
my_func(void)
{
char c;
c = 0x55;
}
#org 0x10000,0x100FF
//========================================
void main()
{
my_func();
while(1);
} |
|
|
|
tanyamahen
Joined: 01 Jul 2004 Posts: 14
|
external_memory |
Posted: Tue Aug 17, 2004 9:53 pm |
|
|
Hi
Thanks for replay..
Ok I think I need tell bit more about what I am really doing...
Ok I have selected EMC -Extended Microcontroller mode (datesheet page71). This mean I can run my code in internal memory and I have access to external memory as well... So I have map the exteranl memory to 0x0fffff - 0x1fffff. ( I am trying to use external memory interface).
Then I selected 16bit byte select mode (datasheet page 75). My hardware similar to figure 6-3 in the datasheet page 75.
The reason for external memory is to store big amount of datas.
So I Try to use build in function....
So my question is... Am I using the build in function correctly...
int writedata[128];
setup_external_memory (EXTMEM_BYTE_SELECT | EXTMEM_WAIT_0);
write_external_memory( 0x0fffff, &writedata, 2);
.............
Thanks for helping me here...
Regards
Tanya |
|
|
|