How to use EEPROM in TG-LPC11U35-501

Dependencies:   AQM0802 EEPROM mbed

Committer:
yasuyuki
Date:
Sun Jun 22 09:57:23 2014 +0000
Revision:
0:8dfee9f6df54
first revision

Who changed what in which revision?

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