JimNewbie Guest
|
Weird problem using external memory driver |
Posted: Sun Mar 29, 2009 5:22 am |
|
|
hi,
I came across this problem and I hope that someone would help me to understand it.
Here is the problematic code:
Code: | #define PIC188F88722_EXT_MEM_START 0x20000L
typedef struct
{
uint32 start_addr;
uint32 end_addr;
uint8 num_block;
} my_test_ext_mem_stype;
my_test_ext_mem_stype my_test_ext_mem;
// This function is having problem
void test_mem_function (void)
{
uint16 temp_read, temp_write, index;
my_test_ext_mem.start_addr = PIC188F88722_EXT_MEM_START ;
for (index = 0; index < 1000; index++)
{
temp_write = index + 33;
write_external_memory(my_test_ext_mem.start_addr ,&temp_write,2);
read_external_memory(my_test_ext_mem.start_addr ,&temp_read,2);
if (temp_write != temp_read)
{
temp_read = temp_write; <<<----- It will hit here alot
}
}
} |
Also the same function, If I modify it like this, my test memory will be passed.
Code: |
void test_mem_function (void)
{
uint16 temp_read, temp_write, index;
uint32 start_address;
start_address = PIC188F88722_EXT_MEM_START ;
for (index = 0; index < 1000; index++)
{
temp_write = index + 33;
write_external_memory(start_address ,&temp_write,2);
read_external_memory(start_address ,&temp_read,2);
if (temp_write != temp_read)
{
temp_read = temp_write; <<<----- won't hit here.
}
}
} |
or like this, still work
Code: | void test_mem_function (void)
{
uint16 temp_read, temp_write, index;
for (index = 0; index < 1000; index++)
{
temp_write = index + 33;
write_external_memory(PIC188F88722_EXT_MEM_START ,&temp_write,2);
read_external_memory(PIC188F88722_EXT_MEM_START ,&temp_read,2);
if (temp_write != temp_read)
{
temp_read = temp_write; <<<----- won't hit here.
}
}
} |
or even this also works
Code: | void test_mem_function (void)
{
uint16 temp_read, temp_write, index;
my_test_ext_mem.start_addr = (PIC188F88722_EXT_MEM_START - 2) ;
for (index = 0; index < 1000; index++)
{
temp_write = index + 33;
write_external_memory(my_test_ext_mem.start_addr + 2 ,&temp_write,2);
read_external_memory(my_test_ext_mem.start_addr + 2,&temp_read,2);
if (temp_write != temp_read)
{
temp_read = temp_write; <<<----- won't hit here. Good to go
}
}
} |
Please help me to explain this kind of weird behavior.
Thank you |
|