I'm developing a product that is similar to the arduino mega. I'm considering using the atmega 640 to save on cost, but I'm having trouble tweaking the arduino Mega bootloader for the 640. It seems simple due to the chips being nearly identical, but I've run into problems. 1 I found there is an instruction ELPM not available on the 640. This seems to be preventing the bootloader code from being a simple port via a few defines. I wondering if anyone could explain what portion of the bootloader code I have to adjust in order to make the 640 work. I believe that the elpm instruction deals with extended memory.
I think this is the problem code
#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega640__) || defined(__AVR_ATmega1281__)
RAMPZ = address_high;
address.word = address.word << 1; //address * 2 -> byte location
/* if ((length.byte & 0x01) == 0x01) length.word++; //Even up an odd number of bytes */
if ((length.byte & 0x01)) length.word++; //Even up an odd number of bytes
cli(); //Disable interrupts, just to be sure
I don't think the RAMPZ register is available in the atmega640 which is why I think the elpm instruction does not exist. I only generally know what going on here any help would be greatly appreciated.