So I wrote a bootloader, tested it on an atmega128, and it worked great.
Now, I'm trying to use it on an atmega16, and i'm having a problem. The
code is supposed to check itself after programming to verify that the
programmed memory matches what it was supposed to program. It's failing
though (on the verify). Am I doing something dumb here..
Address = destination address
PageBuffer = contents to be programmed
// Write data to temporary page
for (page_index = 0; page_index < PageSize; page_index += 2) {
temp_address = Address + (unsigned long) page_index;
temp_data = (uint16_t)(PageBuffer[page_index]) +
((uint16_t)(PageBuffer[page_index+1]) << 8);
boot_page_fill( temp_address, temp_data);
}
// Write page.
boot_page_write((unsigned long)Address);
while(boot_rww_busy()) {
boot_rww_enable();
}
// Check that the page was written correctly
for (page_index=0; page_index<PageSize; page_index++) {
if (PageBuffer[page_index] != pgm_read_byte(Address + page_index)) {
TxChar('$'); /* VERIFY ERROR, RETRY */
break;
}
}