Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #pragma systemFile
00033
00034 #ifndef __COMMON_H__
00035 #include "common.h"
00036 #endif
00037
00038 #define EEPROM_I2C_ADDR 0xA0
00039
00040
00041 #define EEPROM_PAGE_SIZE 128
00042
00043 tByteArray EEPROM_I2CRequest;
00044 tByteArray EEPROM_I2CReply;
00045
00046
00047
00048
00049 bool EEPROMreadBytes(tSensors link, long address, tByteArray &data, int numbytes);
00050 bool EEPROMwriteBytes(tSensors link, long address, tByteArray &data, int numbytes);
00051 bool _EEPROMwriteDummy(tSensors link, long address);
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 bool EEPROMreadBytes(tSensors link, long address, tByteArray &data, int numbytes) {
00063 if (!_EEPROMwriteDummy(link, address))
00064 return false;
00065
00066 memset(EEPROM_I2CRequest, 0, sizeof(tByteArray));
00067
00068 EEPROM_I2CRequest[0] = 1;
00069 EEPROM_I2CRequest[1] = EEPROM_I2C_ADDR;
00070
00071 if (!writeI2C(link, EEPROM_I2CRequest, EEPROM_I2CReply, numbytes))
00072 return false;
00073
00074 memcpy(data, EEPROM_I2CReply, sizeof(tByteArray));
00075 return true;
00076 }
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 bool _EEPROMwriteDummy(tSensors link, long address) {
00088 memset(EEPROM_I2CRequest, 0, sizeof(tByteArray));
00089
00090 EEPROM_I2CRequest[0] = 3;
00091 EEPROM_I2CRequest[1] = EEPROM_I2C_ADDR;
00092 EEPROM_I2CRequest[2] = (byte)((address >> 8) & 0xFF);
00093 EEPROM_I2CRequest[3] = (byte)(address & 0xFF);
00094
00095 return writeI2C(link, EEPROM_I2CRequest);
00096 }
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 bool EEPROMwriteBytes(tSensors link, long address, tByteArray &data, int numbytes) {
00108 memset(EEPROM_I2CRequest, 0, sizeof(tByteArray));
00109
00110 EEPROM_I2CRequest[0] = 3 + numbytes;
00111 EEPROM_I2CRequest[1] = EEPROM_I2C_ADDR;
00112 EEPROM_I2CRequest[2] = (byte)((address >> 8) & 0xFF);
00113 EEPROM_I2CRequest[3] = (byte)(address & 0xFF);
00114
00115 if (numbytes > 13)
00116 numbytes = 13;
00117
00118 if (numbytes < 0)
00119 numbytes = 0;
00120
00121 memcpy(&EEPROM_I2CRequest[4], &data[0], numbytes);
00122 return writeI2C(link, EEPROM_I2CRequest);
00123 }
00124
00125
00126
00127
00128
00129