AVR910 In-System Programming

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /**
00002  * Program an AVR with an mbed.
00003  */
00004  
00005 // ATMega328 Datasheet:
00006 //
00007 //  http://www.atmel.com/dyn/resources/prod_documents/doc8271.pdf
00008 
00009 #include "AVR910.h"
00010 
00011 LocalFileSystem local("local");
00012 Serial pc(USBTX, USBRX);
00013 
00014 AVR910 mbedISP(p5, p6, p7, p8); //mosi, miso, sclk, nreset.
00015 
00016 int main() {
00017 
00018     int success = -1;
00019     
00020     FILE *fp = fopen(PATH_TO_BINARY, "rb");
00021     
00022     if(fp == NULL){
00023         pc.printf("Failed to open binary. Please check the file path\n");
00024     }
00025     else{
00026         pc.printf("Binary file opened successfully\n");
00027         success = mbedISP.program(fp);
00028         fclose(fp);
00029     }
00030     
00031     if(success < 0){
00032         printf("Programming failed.\n");
00033     }
00034     else{
00035         printf("Programming was successful!\n");
00036     }
00037     
00038 }