Program an AVR microcontroller using mbed.

Dependencies:   mbed

Revision:
2:99c56829a2a8
Parent:
1:276f6df4be7a
--- a/AVR910.cpp	Wed Sep 01 10:22:51 2010 +0000
+++ b/AVR910.cpp	Thu Sep 09 11:11:37 2010 +0000
@@ -91,6 +91,7 @@
 
     char pageOffset = 0;
     int  pageNumber = 0;
+    int  address    = 0;
     int  c          = 0;
     int  highLow    = 0;
 
@@ -132,16 +133,19 @@
 
             //Write low byte.
             if (highLow == 0) {
-                loadMemoryPage(WRITE_LOW_BYTE, pageOffset, c);
+                writeFlashMemoryByte(WRITE_LOW_FLASH_BYTE, address, c);
                 highLow = 1;
             }
             //Write high byte.
             else {
-                loadMemoryPage(WRITE_HIGH_BYTE, pageOffset, c);
+                writeFlashMemoryByte(WRITE_HIGH_FLASH_BYTE, address, c);
                 highLow = 0;
-                pageOffset++;
+                address++;
 
-                if (pageOffset > pageSize) {
+                //Page size is our memory size in the non-paged memory case.
+                //Therefore if we've gone beyond our size break because we
+                //don't have any more room.
+                if (address > pageSize) {
                     break;
                 }
 
@@ -280,6 +284,15 @@
 
 }
 
+void AVR910::writeFlashMemoryByte(int highLow, int address, char data) {
+
+    spi_.write(highLow);
+    spi_.write(address & 0xFF00 >> 8);
+    spi_.write(address & 0x00FF);
+    spi_.write(data);
+
+}
+
 void AVR910::writeFlashMemoryPage(char pageNumber) {
 
     spi_.write(0x4C);