EEPROM Demo - MBED + SmartGPU2 board

Dependencies:   SMARTGPU2 mbed

Committer:
emmanuelchio
Date:
Thu Apr 17 21:41:30 2014 +0000
Revision:
1:ccc3b08131c8
Parent:
0:1e62f3fc1154
SmartGPU2 EEPROM_SG2 demo- Please select(uncomment) your smartGPU2 board under SMARTGPU2.h file before compiling!!!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emmanuelchio 1:ccc3b08131c8 1 /**************************************************************************************/
emmanuelchio 0:1e62f3fc1154 2 /**************************************************************************************/
emmanuelchio 0:1e62f3fc1154 3 /*SMARTGPU2 intelligent embedded graphics processor unit
emmanuelchio 1:ccc3b08131c8 4 those examples are for using the SMARTGPU2 with the mbed microcontoller, just connect tx,rx,and reset
emmanuelchio 0:1e62f3fc1154 5 Board:
emmanuelchio 1:ccc3b08131c8 6 http://www.vizictechnologies.com/
emmanuelchio 0:1e62f3fc1154 7
emmanuelchio 0:1e62f3fc1154 8 www.vizictechnologies.com
emmanuelchio 1:ccc3b08131c8 9 Vizic Technologies copyright 2014 */
emmanuelchio 1:ccc3b08131c8 10 /**************************************************************************************/
emmanuelchio 0:1e62f3fc1154 11 /**************************************************************************************/
emmanuelchio 0:1e62f3fc1154 12
emmanuelchio 0:1e62f3fc1154 13 /********************************************************
emmanuelchio 0:1e62f3fc1154 14 This simple sketch does the next:
emmanuelchio 0:1e62f3fc1154 15 1.- init/Clear EEPROM buffer with 0xFF - EEPROM buffer size is 2048 (2k)
emmanuelchio 0:1e62f3fc1154 16 2.- write data 10 times to EEPROM buffer "0123456789"
emmanuelchio 0:1e62f3fc1154 17 3.- compare EEPROM buffer contents with EEPROM PAGE0, if equal go to step 7, if not continue to step 4
emmanuelchio 0:1e62f3fc1154 18 4.- erase EEPROM PAGE0
emmanuelchio 0:1e62f3fc1154 19 5.- save current EEPROM buffer contents(100 x "0123456789") to EEPROM PAGE0
emmanuelchio 0:1e62f3fc1154 20 6.- compare again EEPROM buffer contents with EEPROM PAGE0
emmanuelchio 0:1e62f3fc1154 21 7.- show results on display
emmanuelchio 0:1e62f3fc1154 22 8.- end
emmanuelchio 0:1e62f3fc1154 23
emmanuelchio 0:1e62f3fc1154 24 - once executed the above, remove power from SmartGPU and run sketch again, EEPROM contents will remain as they are non-volatile data
emmanuelchio 0:1e62f3fc1154 25 ********************************************************/
emmanuelchio 0:1e62f3fc1154 26
emmanuelchio 0:1e62f3fc1154 27 #include "mbed.h"
emmanuelchio 0:1e62f3fc1154 28 #include "SMARTGPU2.h"
emmanuelchio 0:1e62f3fc1154 29
emmanuelchio 0:1e62f3fc1154 30 SMARTGPU2 lcd(TXPIN,RXPIN,RESETPIN); //create our object called "lcd"
emmanuelchio 0:1e62f3fc1154 31
emmanuelchio 0:1e62f3fc1154 32 unsigned int row=10;
emmanuelchio 0:1e62f3fc1154 33
emmanuelchio 0:1e62f3fc1154 34 /***************************************************/
emmanuelchio 0:1e62f3fc1154 35 /***************************************************/
emmanuelchio 0:1e62f3fc1154 36 void initializeSmartGPU2(void){ //Initialize SMARTGPU2 Board
emmanuelchio 0:1e62f3fc1154 37 lcd.reset(); //physically reset SMARTGPU2
emmanuelchio 0:1e62f3fc1154 38 lcd.start(); //initialize the SMARTGPU2 processor
emmanuelchio 0:1e62f3fc1154 39 }
emmanuelchio 0:1e62f3fc1154 40
emmanuelchio 0:1e62f3fc1154 41 /***************************************************/
emmanuelchio 0:1e62f3fc1154 42 /***************************************************/
emmanuelchio 0:1e62f3fc1154 43 /***************************************************/
emmanuelchio 0:1e62f3fc1154 44 /***************************************************/
emmanuelchio 0:1e62f3fc1154 45 int main() {
emmanuelchio 0:1e62f3fc1154 46 NUMBEROFBYTES charsPrinted;
emmanuelchio 0:1e62f3fc1154 47 char data[]="0123456789";
emmanuelchio 0:1e62f3fc1154 48 unsigned int i=0;
emmanuelchio 0:1e62f3fc1154 49 unsigned char result=0;
emmanuelchio 0:1e62f3fc1154 50
emmanuelchio 0:1e62f3fc1154 51 initializeSmartGPU2(); //Init communication with SmartGPU2 board
emmanuelchio 1:ccc3b08131c8 52 lcd.baudChange(BAUD6); //set a fast baud! for fast drawing
emmanuelchio 0:1e62f3fc1154 53
emmanuelchio 0:1e62f3fc1154 54 //strings config
emmanuelchio 0:1e62f3fc1154 55 lcd.setTextColour(GREEN);
emmanuelchio 0:1e62f3fc1154 56 lcd.string(10,row,319,239,"EEPROM page open, read, write demo!",&charsPrinted); row+=30;
emmanuelchio 0:1e62f3fc1154 57 lcd.string(10,row,319,239,"Performing procedure...",&charsPrinted); row+=30;
emmanuelchio 0:1e62f3fc1154 58
emmanuelchio 0:1e62f3fc1154 59 //ONCE WE START USING EEPROM BUFFER WE CAN'T CALL OTHER SMARTGPU FUNCTIONS DIFFERENT THAN EEPROM 'E' FUNCTIONS, AS EEPROM BUFFER WILL BE DISCARDED IF SO
emmanuelchio 0:1e62f3fc1154 60 //init/Clear EEPROM buffer with 0xFF values
emmanuelchio 0:1e62f3fc1154 61 lcd.initClearEEPROMBuff();
emmanuelchio 0:1e62f3fc1154 62
emmanuelchio 0:1e62f3fc1154 63 //write data array 10 times to EEPROM buffer
emmanuelchio 0:1e62f3fc1154 64 for(i=0; i < 10; i++){
emmanuelchio 0:1e62f3fc1154 65 lcd.writeEEPROMBuff(data, i*10, 10, &charsPrinted);
emmanuelchio 0:1e62f3fc1154 66 }
emmanuelchio 0:1e62f3fc1154 67
emmanuelchio 0:1e62f3fc1154 68 //verify contents - EEPROM buffer contents vs EEPROM PAGE0
emmanuelchio 0:1e62f3fc1154 69 lcd.compBuffToEEPROMPage(PAGE0, &result); //compare EEPROM buffer contents with EEPROM PAGE0
emmanuelchio 0:1e62f3fc1154 70
emmanuelchio 0:1e62f3fc1154 71 if(result == 1){ //if contents are equal - means that data was already written and its equal
emmanuelchio 0:1e62f3fc1154 72 lcd.string(10,row,319,239,"EEPROM PAGE0 Contents were already equal...END",&charsPrinted);
emmanuelchio 0:1e62f3fc1154 73 }else{ //if contents are different - erase PAGE0 and write EEPROM buffer into PAGE0 - This procedure will be executed only the veryfirst time
emmanuelchio 0:1e62f3fc1154 74 //erase EEPROM PAGE0
emmanuelchio 0:1e62f3fc1154 75 lcd.eraseEEPROMPage(PAGE0);
emmanuelchio 0:1e62f3fc1154 76 //save current EEPROM buffer contents(100 x "0123456789") to EEPROM PAGE0
emmanuelchio 0:1e62f3fc1154 77 lcd.saveBuffToEEPROMPage(PAGE0);
emmanuelchio 0:1e62f3fc1154 78 //verify contents again - EEPROM buffer contents vs EEPROM PAGE0
emmanuelchio 0:1e62f3fc1154 79 lcd.compBuffToEEPROMPage(PAGE0, &result); //compare EEPROM buffer contents with EEPROM PAGE0
emmanuelchio 0:1e62f3fc1154 80 if(result == 1){ //if contents are equal
emmanuelchio 0:1e62f3fc1154 81 lcd.string(10,row,319,239,"New EEPROM PAGE0 Contents are equal...END",&charsPrinted);
emmanuelchio 0:1e62f3fc1154 82 }else{ //error
emmanuelchio 0:1e62f3fc1154 83 lcd.string(10,row,319,239,"New EEPROM PAGE0 Contents differ...END",&charsPrinted);
emmanuelchio 0:1e62f3fc1154 84 }
emmanuelchio 0:1e62f3fc1154 85 }
emmanuelchio 0:1e62f3fc1154 86
emmanuelchio 0:1e62f3fc1154 87 //loop forever
emmanuelchio 0:1e62f3fc1154 88 while(1);
emmanuelchio 0:1e62f3fc1154 89 }