Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-STM32F103C8T6 SHT21_ncleee
eeprom.cpp
00001 #include "eeprom.h" 00002 #include "main.h" 00003 00004 void readID(int addy){ 00005 char ucdata_write[1]; 00006 char ucdata_read[1]; 00007 ucdata_write[0] = addy; //MCP24AA02_DID, Address here for Device ID 00008 while (i2c.write((MCP24AA02_ADDR|WRITE), ucdata_write, 1, 0)){;}//Wait for ACK if EEPROM is in 'write' cycle 00009 i2c.read((MCP24AA02_ADDR|READ),ucdata_read,1,0); 00010 if(ucdata_read[0]==0x29){ 00011 debug_uart.printf("Code=%#x (Microchip Technology ltd.(c))\r\n",ucdata_read[0]); 00012 } 00013 if(ucdata_read[0]==0x41){ 00014 debug_uart.printf("Code=%#x (2K EEPROM Using i2c)\r\n",ucdata_read[0]); 00015 }else{ 00016 debug_uart.printf("Unknown eeprom device %x\r\n", ucdata_read[0]); 00017 } 00018 } 00019 00020 void readEE(int addy){ 00021 char ucdata_write[1]; 00022 char ucdata_read[1]; 00023 ucdata_write[0] = addy; //Address here to read 00024 while (i2c.write((MCP24AA02_ADDR|WRITE), ucdata_write, 1, 0)){} //Wait for ACK if EEPROM is in 'write' cycle 00025 i2c.read((MCP24AA02_ADDR|READ),ucdata_read,1,0); //Note 'OR' Address with Read bit 00026 debug_uart.printf("%c",ucdata_read[0]); 00027 } 00028 00029 void writeEE(int addy,int data){ 00030 char ucdata_write[2]; 00031 ucdata_write[0] = addy; 00032 ucdata_write[1] = data; 00033 while (i2c.write((MCP24AA02_ADDR|WRITE), ucdata_write, 1, 0)){} //Wait for ACK if EEPROM is in 'write' cycle 00034 i2c.write((MCP24AA02_ADDR|WRITE),ucdata_write,2,0); //Note 'OR' Adress with Write bit 00035 debug_uart.printf("%04d %c\t",addy,data); 00036 } 00037 00038 void eraseEE(void){ 00039 for (int i=0;i<0xFA;i++){ //0xFA to 0xFF are read only with Manufacture/Hardware ID and a Unique Serial Number 00040 writeEE(i,0xFF); 00041 } 00042 }
Generated on Wed Jul 13 2022 01:09:48 by
1.7.2