feng wang / Mbed OS ACTest_ForHank

Dependencies:   mbed-STM32F103C8T6 SHT21_ncleee

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers eeprom.cpp Source File

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 }