Read Program Memory problems in the mega48

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am attempting to program a mega48 from a mega128 over the spi and am having some difficulty with the read program memory instruction. The mega48 programs fine but any address i attempt to read returns 0x0000. Any advice would be appreciated. The code i am using to read is below.
Compiler: Codevision
Languace: C
Emulator: JTAG
Code:

/************************************* Read Program Memory ************************************************/
unsigned int read_program_memory(unsigned int address)
{ // Read a word from the program memory
unsigned char temp;
unsigned int data;
temp = spi(0x20); // Send the command to read the low byte of a program memory word
temp = spi((unsigned char)(address >> 8)); // Send the high byte of the address of the word being read
temp = spi((unsigned char)address); // Send the low byte of the address of the word being read
data = (unsigned int)spi(0x00); // Read the low byte of the program memory word
temp = spi(0x28); // Send the command to read the low byte of a program memory word
temp = spi((unsigned char)(address >> 8)); // Send the high byte of the address of the word being read
temp = spi((unsigned char)address); // Send the low byte of the address of the word being read
data |= ((unsigned int)spi(0x00) << 8); // Read the high byte of the program memory word
return data; // Return the program memory word read
}
/*******************************************************************************************************/

I know it's not the most efficient implimentation....but it's easy to read......or at least would be if my spacing pasted right. :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
......or at least would be if my spacing pasted right.

Try out the "Code" feature:

************************************* Read Program Memory ************************************************/ 
unsigned int read_program_memory(unsigned int address) 
{ // Read a word from the program memory 
unsigned char temp; 
unsigned int data; 
temp = spi(0x20); // Send the command to read the low byte of a program memory word 
temp = spi((unsigned char)(address >> 8)); // Send the high byte of the address of the word being read 
temp = spi((unsigned char)address); // Send the low byte of the address of the word being read 
data = (unsigned int)spi(0x00); // Read the low byte of the program memory word 
temp = spi(0x28); // Send the command to read the low byte of a program memory word 
temp = spi((unsigned char)(address >> 8)); // Send the high byte of the address of the word being read 
temp = spi((unsigned char)address); // Send the low byte of the address of the word being read 
data |= ((unsigned int)spi(0x00) << 8); // Read the high byte of the program memory word 
return data; // Return the program memory word read 
} 
/*******************************************************************************************************/ 

Next, how did you get your hands on a Mega48?

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Lee.....guess i should have looked at the tags before submitting :)
As far as how i got them.....a ski mask and baseball bat go a long way.........
But really, we've managed to get ahold of a few samples here at work....wish i could say where from...but i really have no idea

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

holy cow...you have mega48 samples? are they the 28 DIP package by chance? any chance you know if you just got them from your local rep? what area are you in?

I'm very curious since I've been trying to sample one for over a month now, with no luck....whats the trick?

Salivating over the possibilities,
John

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry John, all we have is the 32pin tqfp. No idea on where they came from though...we just tell our purchasing guy what we need and he gets it. I'm located in central Illinois if that's any help though.