EEPROM in TG-LPC11U35-501

Dependents:   mbed_EEPROM USBMSD_step1 USBMSD_step1_5

See https://mbed.org/users/yasuyuki/notebook/EEPROM/

Committer:
yasuyuki
Date:
Thu Jun 26 13:45:34 2014 +0000
Revision:
0:25e5bc71e65f
first revision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yasuyuki 0:25e5bc71e65f 1 //**********************
yasuyuki 0:25e5bc71e65f 2 // EEPROM.cpp for TG-LPC11U35-501
yasuyuki 0:25e5bc71e65f 3 // TG-LPC11U35-501 has 4K EEPROM.
yasuyuki 0:25e5bc71e65f 4 //
yasuyuki 0:25e5bc71e65f 5 // usage:
yasuyuki 0:25e5bc71e65f 6 // EEPROM eeprom;
yasuyuki 0:25e5bc71e65f 7 // char RAM[100]
yasuyuki 0:25e5bc71e65f 8 // eeprom.write(0, RAM, 100);
yasuyuki 0:25e5bc71e65f 9 // eeprom.read(0, RAM, 100);
yasuyuki 0:25e5bc71e65f 10 // eeprom.put(0, 0x00);
yasuyuki 0:25e5bc71e65f 11 // i=eeprom.get(0);
yasuyuki 0:25e5bc71e65f 12 //
yasuyuki 0:25e5bc71e65f 13 // note:
yasuyuki 0:25e5bc71e65f 14 // valid EEPROM address range is between 0 to 4031
yasuyuki 0:25e5bc71e65f 15 // top 64 bytes are reserved
yasuyuki 0:25e5bc71e65f 16 //
yasuyuki 0:25e5bc71e65f 17 // (C)Copyright 2014 All rights reserved by Y.Onodera
yasuyuki 0:25e5bc71e65f 18 // http://einstlab.web.fc2.com
yasuyuki 0:25e5bc71e65f 19 //**********************
yasuyuki 0:25e5bc71e65f 20 #include "EEPROM.h"
yasuyuki 0:25e5bc71e65f 21
yasuyuki 0:25e5bc71e65f 22 int EEPROM::write( unsigned int EEPROM_addr, char *RAM_addr, unsigned int n ) {
yasuyuki 0:25e5bc71e65f 23 command[0] = EEPROM_Write;
yasuyuki 0:25e5bc71e65f 24 command[1] = EEPROM_addr;
yasuyuki 0:25e5bc71e65f 25 command[2] = (unsigned int)RAM_addr;
yasuyuki 0:25e5bc71e65f 26 command[3] = n;
yasuyuki 0:25e5bc71e65f 27 command[4] = cclk_kHz;
yasuyuki 0:25e5bc71e65f 28
yasuyuki 0:25e5bc71e65f 29 iap_entry( command, status );
yasuyuki 0:25e5bc71e65f 30
yasuyuki 0:25e5bc71e65f 31 return ( (int)status[0] );
yasuyuki 0:25e5bc71e65f 32 }
yasuyuki 0:25e5bc71e65f 33
yasuyuki 0:25e5bc71e65f 34
yasuyuki 0:25e5bc71e65f 35 int EEPROM::read( unsigned int EEPROM_addr, char *RAM_addr, unsigned int n ) {
yasuyuki 0:25e5bc71e65f 36 command[0] = EEPROM_Read;
yasuyuki 0:25e5bc71e65f 37 command[1] = EEPROM_addr;
yasuyuki 0:25e5bc71e65f 38 command[2] = (unsigned int)RAM_addr;
yasuyuki 0:25e5bc71e65f 39 command[3] = n;
yasuyuki 0:25e5bc71e65f 40 command[4] = cclk_kHz;
yasuyuki 0:25e5bc71e65f 41
yasuyuki 0:25e5bc71e65f 42 iap_entry( command, status );
yasuyuki 0:25e5bc71e65f 43
yasuyuki 0:25e5bc71e65f 44 return ( (int)status[0] );
yasuyuki 0:25e5bc71e65f 45 }
yasuyuki 0:25e5bc71e65f 46
yasuyuki 0:25e5bc71e65f 47
yasuyuki 0:25e5bc71e65f 48 int EEPROM::put( unsigned int EEPROM_addr, char data ) {
yasuyuki 0:25e5bc71e65f 49 dat[0]=data;
yasuyuki 0:25e5bc71e65f 50 command[0] = EEPROM_Write;
yasuyuki 0:25e5bc71e65f 51 command[1] = EEPROM_addr;
yasuyuki 0:25e5bc71e65f 52 command[2] = (unsigned int)dat;
yasuyuki 0:25e5bc71e65f 53 command[3] = 1;
yasuyuki 0:25e5bc71e65f 54 command[4] = cclk_kHz;
yasuyuki 0:25e5bc71e65f 55
yasuyuki 0:25e5bc71e65f 56 iap_entry( command, status );
yasuyuki 0:25e5bc71e65f 57
yasuyuki 0:25e5bc71e65f 58 return ( (int)status[0] );
yasuyuki 0:25e5bc71e65f 59 }
yasuyuki 0:25e5bc71e65f 60
yasuyuki 0:25e5bc71e65f 61
yasuyuki 0:25e5bc71e65f 62 char EEPROM::get( unsigned int EEPROM_addr ) {
yasuyuki 0:25e5bc71e65f 63 command[0] = EEPROM_Read;
yasuyuki 0:25e5bc71e65f 64 command[1] = EEPROM_addr;
yasuyuki 0:25e5bc71e65f 65 command[2] = (unsigned int)dat;
yasuyuki 0:25e5bc71e65f 66 command[3] = 1;
yasuyuki 0:25e5bc71e65f 67 command[4] = cclk_kHz;
yasuyuki 0:25e5bc71e65f 68
yasuyuki 0:25e5bc71e65f 69 iap_entry( command, status );
yasuyuki 0:25e5bc71e65f 70
yasuyuki 0:25e5bc71e65f 71 return ( dat[0] );
yasuyuki 0:25e5bc71e65f 72 }