1,098 Views 2 Replies Last post: Jul 31, 2009 4:30 AM by Tisho RSS
Tisho Newbie 19 posts since
Oct 28, 2008
Currently Being Moderated

Jul 30, 2009 6:25 AM

M32C87 external memory array.

Hello,

How  to use "unsigned long" in external RAM array?

here is the example code:

 

#pragma ADDRESS ext_mem  200000H    // External RAM start address

far unsigned long ext_mem;

 

void main (void) {

 

ext_mem = 0x12345678;

 

}

 

After check address 200000H i saw strange results in adrress 200000H  has correct results(1234H), but in address 200001H the results is diferent than 5678H.

External ram is 16 bit wide, NC308 has not give errors. 

What i wrong?

DJ Delorie Novice 301 posts since
Mar 12, 2009
Currently Being Moderated
Jul 30, 2009 11:01 AM in response to: Tisho
Re: M32C87 external memory array.

A couple of observations...

 

First off, you need to use 0x12345678L (note the L) to create a "long" constant; otherwise you may end up accidentally truncating it.

 

Second, the m32c is little-endian, so memory contents should be as follows (all hex):

200000  78

200001  56

200002  34

200004  12

 

If you look at them as 16-bit locations:

200000 5678

200002 1234

 

If you're not getting these values, it's time to check the hardware.  For 16-bit memory, make sure you did NOT use the A0 address line.  Also, double check your timing.  Try this program (assuming you have a suitable printf), first WITHOUT the pragma (to see how it should work), then WITH (to test the memory connections):

 

#include <stdio.h>

 

unsigned long x;

 

main()
{
  unsigned char *cp;
  int i;

 

  x = 0x12345678;
  cp = (unsigned char *)&x;
  for (i=0; i<4; i++)
    printf(" %02x", cp[i]);
  printf("\n");
}

More Like This

  • Retrieving data ...

Bookmarked By (0)