1Mbit EEPROMを便利に使うためのライブラリ

Dependents:   EEPROM_Reset_Program EEPROM_Encode_Program SWAN_IZU2019_v1

Committer:
Sigma884
Date:
Tue Feb 12 15:44:54 2019 +0000
Revision:
3:d040fa9b5bb9
Parent:
1:66c2c82f4b34
Turn of Writing changed. 3,2,1,0 -> 0,1,2,3. for using Encode Program.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sigma884 0:a945081a4a9e 1 #include "mbed.h"
Sigma884 0:a945081a4a9e 2 #include "EEPROM_lib.h"
Sigma884 0:a945081a4a9e 3
Sigma884 0:a945081a4a9e 4 EEPROM_lib::EEPROM_lib(I2C &user_i2c, int num){
Sigma884 0:a945081a4a9e 5 i2c = &user_i2c;
Sigma884 0:a945081a4a9e 6 i2c -> frequency(400000);
Sigma884 0:a945081a4a9e 7
Sigma884 0:a945081a4a9e 8 max_num = num;
Sigma884 0:a945081a4a9e 9 buff_ptr = 0;
Sigma884 0:a945081a4a9e 10 ptr[3] = ptr[2] = ptr[1] = ptr[0] = 0x00;
Sigma884 0:a945081a4a9e 11 }
Sigma884 0:a945081a4a9e 12
Sigma884 0:a945081a4a9e 13 void EEPROM_lib::writeByte(int num, int block, char ADDR_H, char ADDR_L, char DATA){
Sigma884 0:a945081a4a9e 14 if(num > max_num){
Sigma884 0:a945081a4a9e 15 return;
Sigma884 0:a945081a4a9e 16 }
Sigma884 0:a945081a4a9e 17 switch(num){
Sigma884 0:a945081a4a9e 18 case 1:
Sigma884 0:a945081a4a9e 19 slave = EEPROM_ADDR_00_0;
Sigma884 0:a945081a4a9e 20 break;
Sigma884 0:a945081a4a9e 21
Sigma884 0:a945081a4a9e 22 case 2:
Sigma884 0:a945081a4a9e 23 slave = EEPROM_ADDR_01_0;
Sigma884 0:a945081a4a9e 24 break;
Sigma884 0:a945081a4a9e 25
Sigma884 0:a945081a4a9e 26 case 3:
Sigma884 0:a945081a4a9e 27 slave = EEPROM_ADDR_10_0;
Sigma884 0:a945081a4a9e 28 break;
Sigma884 0:a945081a4a9e 29
Sigma884 0:a945081a4a9e 30 case 4:
Sigma884 0:a945081a4a9e 31 slave = EEPROM_ADDR_11_0;
Sigma884 0:a945081a4a9e 32 break;
Sigma884 0:a945081a4a9e 33 }
Sigma884 0:a945081a4a9e 34 if(block == 1){
Sigma884 0:a945081a4a9e 35 slave = slave | 0x08;
Sigma884 0:a945081a4a9e 36 }
Sigma884 0:a945081a4a9e 37 cmd[0] = ADDR_H;
Sigma884 0:a945081a4a9e 38 cmd[1] = ADDR_L;
Sigma884 0:a945081a4a9e 39 cmd[2] = DATA;
Sigma884 0:a945081a4a9e 40
Sigma884 0:a945081a4a9e 41 i2c -> write(slave, cmd, 3);
Sigma884 0:a945081a4a9e 42 wait_us(EEPROM_WAIT_US);
Sigma884 0:a945081a4a9e 43 }
Sigma884 0:a945081a4a9e 44
Sigma884 0:a945081a4a9e 45 void EEPROM_lib::writePage(int num, int block, char ADDR_H, char ADDR_L, char *DATA){
Sigma884 0:a945081a4a9e 46 if(num > max_num){
Sigma884 0:a945081a4a9e 47 return;
Sigma884 0:a945081a4a9e 48 }
Sigma884 0:a945081a4a9e 49 switch(num){
Sigma884 0:a945081a4a9e 50 case 1:
Sigma884 0:a945081a4a9e 51 slave = EEPROM_ADDR_00_0;
Sigma884 0:a945081a4a9e 52 break;
Sigma884 0:a945081a4a9e 53
Sigma884 0:a945081a4a9e 54 case 2:
Sigma884 0:a945081a4a9e 55 slave = EEPROM_ADDR_01_0;
Sigma884 0:a945081a4a9e 56 break;
Sigma884 0:a945081a4a9e 57
Sigma884 0:a945081a4a9e 58 case 3:
Sigma884 0:a945081a4a9e 59 slave = EEPROM_ADDR_10_0;
Sigma884 0:a945081a4a9e 60 break;
Sigma884 0:a945081a4a9e 61
Sigma884 0:a945081a4a9e 62 case 4:
Sigma884 0:a945081a4a9e 63 slave = EEPROM_ADDR_11_0;
Sigma884 0:a945081a4a9e 64 break;
Sigma884 0:a945081a4a9e 65 }
Sigma884 0:a945081a4a9e 66 if(block == 1){
Sigma884 0:a945081a4a9e 67 slave = slave | 0x08;
Sigma884 0:a945081a4a9e 68 }
Sigma884 0:a945081a4a9e 69 cmd[0] = ADDR_H;
Sigma884 0:a945081a4a9e 70 cmd[1] = ADDR_L;
Sigma884 0:a945081a4a9e 71 for(int i = 2; i < 130; i ++){
Sigma884 0:a945081a4a9e 72 cmd[i] = DATA[i-2];
Sigma884 0:a945081a4a9e 73 }
Sigma884 0:a945081a4a9e 74
Sigma884 0:a945081a4a9e 75 i2c -> write(slave, cmd, 130);
Sigma884 0:a945081a4a9e 76 wait_us(EEPROM_WAIT_US);
Sigma884 0:a945081a4a9e 77 }
Sigma884 0:a945081a4a9e 78
Sigma884 0:a945081a4a9e 79 void EEPROM_lib::setWriteAddr(int num, int block, char ADDR_H, char ADDR_L){
Sigma884 0:a945081a4a9e 80 if(num > max_num){
Sigma884 0:a945081a4a9e 81 return;
Sigma884 0:a945081a4a9e 82 }
Sigma884 0:a945081a4a9e 83 switch(num){
Sigma884 0:a945081a4a9e 84 case 1:
Sigma884 0:a945081a4a9e 85 slave = EEPROM_ADDR_00_0;
Sigma884 0:a945081a4a9e 86 break;
Sigma884 0:a945081a4a9e 87
Sigma884 0:a945081a4a9e 88 case 2:
Sigma884 0:a945081a4a9e 89 slave = EEPROM_ADDR_01_0;
Sigma884 0:a945081a4a9e 90 break;
Sigma884 0:a945081a4a9e 91
Sigma884 0:a945081a4a9e 92 case 3:
Sigma884 0:a945081a4a9e 93 slave = EEPROM_ADDR_10_0;
Sigma884 0:a945081a4a9e 94 break;
Sigma884 0:a945081a4a9e 95
Sigma884 0:a945081a4a9e 96 case 4:
Sigma884 0:a945081a4a9e 97 slave = EEPROM_ADDR_11_0;
Sigma884 0:a945081a4a9e 98 break;
Sigma884 0:a945081a4a9e 99 }
Sigma884 0:a945081a4a9e 100 if(block == 1){
Sigma884 0:a945081a4a9e 101 slave = slave | 0x08;
Sigma884 0:a945081a4a9e 102 }
Sigma884 0:a945081a4a9e 103 cmd[0] = ADDR_H;
Sigma884 0:a945081a4a9e 104 cmd[1] = ADDR_L;
Sigma884 0:a945081a4a9e 105 }
Sigma884 0:a945081a4a9e 106
Sigma884 0:a945081a4a9e 107 int EEPROM_lib::chargeBuff(char DATA){
Sigma884 0:a945081a4a9e 108 if(buff_ptr < 128){
Sigma884 0:a945081a4a9e 109 EEPROM_cast.c = DATA;
Sigma884 0:a945081a4a9e 110 cmd[buff_ptr + 2] = EEPROM_cast.cast[0];
Sigma884 0:a945081a4a9e 111
Sigma884 0:a945081a4a9e 112 buff_ptr ++;
Sigma884 0:a945081a4a9e 113 }
Sigma884 0:a945081a4a9e 114 return buff_ptr;
Sigma884 0:a945081a4a9e 115 }
Sigma884 0:a945081a4a9e 116
Sigma884 0:a945081a4a9e 117 int EEPROM_lib::chargeBuff(bool DATA){
Sigma884 0:a945081a4a9e 118 if(buff_ptr < 128){
Sigma884 0:a945081a4a9e 119 EEPROM_cast.b = DATA;
Sigma884 0:a945081a4a9e 120 cmd[buff_ptr + 2] = EEPROM_cast.cast[0];
Sigma884 0:a945081a4a9e 121
Sigma884 0:a945081a4a9e 122 buff_ptr ++;
Sigma884 0:a945081a4a9e 123 }
Sigma884 0:a945081a4a9e 124 return buff_ptr;
Sigma884 0:a945081a4a9e 125 }
Sigma884 0:a945081a4a9e 126
Sigma884 0:a945081a4a9e 127 int EEPROM_lib::chargeBuff(int DATA){
Sigma884 0:a945081a4a9e 128 if(buff_ptr < 128 - 3){
Sigma884 0:a945081a4a9e 129 EEPROM_cast.i = DATA;
Sigma884 3:d040fa9b5bb9 130 cmd[buff_ptr + 2] = EEPROM_cast.cast[0];
Sigma884 3:d040fa9b5bb9 131 cmd[buff_ptr + 3] = EEPROM_cast.cast[1];
Sigma884 3:d040fa9b5bb9 132 cmd[buff_ptr + 4] = EEPROM_cast.cast[2];
Sigma884 3:d040fa9b5bb9 133 cmd[buff_ptr + 5] = EEPROM_cast.cast[3];
Sigma884 0:a945081a4a9e 134
Sigma884 0:a945081a4a9e 135 buff_ptr += 4;
Sigma884 0:a945081a4a9e 136 }
Sigma884 0:a945081a4a9e 137 return buff_ptr;
Sigma884 0:a945081a4a9e 138 }
Sigma884 0:a945081a4a9e 139
Sigma884 0:a945081a4a9e 140 int EEPROM_lib::chargeBuff(short DATA){
Sigma884 0:a945081a4a9e 141 if(buff_ptr < 128 - 1){
Sigma884 0:a945081a4a9e 142 EEPROM_cast.s = DATA;
Sigma884 3:d040fa9b5bb9 143 cmd[buff_ptr + 2] = EEPROM_cast.cast[0];
Sigma884 3:d040fa9b5bb9 144 cmd[buff_ptr + 3] = EEPROM_cast.cast[1];
Sigma884 0:a945081a4a9e 145
Sigma884 0:a945081a4a9e 146 buff_ptr += 2;
Sigma884 0:a945081a4a9e 147 }
Sigma884 0:a945081a4a9e 148 return buff_ptr;
Sigma884 0:a945081a4a9e 149 }
Sigma884 0:a945081a4a9e 150
Sigma884 0:a945081a4a9e 151 int EEPROM_lib::chargeBuff(long long DATA){
Sigma884 0:a945081a4a9e 152 if(buff_ptr < 128 - 7){
Sigma884 0:a945081a4a9e 153 EEPROM_cast.ll = DATA;
Sigma884 3:d040fa9b5bb9 154 cmd[buff_ptr + 2] = EEPROM_cast.cast[0];
Sigma884 3:d040fa9b5bb9 155 cmd[buff_ptr + 3] = EEPROM_cast.cast[1];
Sigma884 3:d040fa9b5bb9 156 cmd[buff_ptr + 4] = EEPROM_cast.cast[2];
Sigma884 3:d040fa9b5bb9 157 cmd[buff_ptr + 5] = EEPROM_cast.cast[3];
Sigma884 3:d040fa9b5bb9 158 cmd[buff_ptr + 6] = EEPROM_cast.cast[4];
Sigma884 3:d040fa9b5bb9 159 cmd[buff_ptr + 7] = EEPROM_cast.cast[5];
Sigma884 3:d040fa9b5bb9 160 cmd[buff_ptr + 8] = EEPROM_cast.cast[6];
Sigma884 3:d040fa9b5bb9 161 cmd[buff_ptr + 9] = EEPROM_cast.cast[7];
Sigma884 0:a945081a4a9e 162
Sigma884 0:a945081a4a9e 163 buff_ptr += 8;
Sigma884 0:a945081a4a9e 164 }
Sigma884 0:a945081a4a9e 165 return buff_ptr;
Sigma884 0:a945081a4a9e 166 }
Sigma884 0:a945081a4a9e 167
Sigma884 0:a945081a4a9e 168 int EEPROM_lib::chargeBuff(float DATA){
Sigma884 0:a945081a4a9e 169 if(buff_ptr < 128 - 3){
Sigma884 0:a945081a4a9e 170 EEPROM_cast.f = DATA;
Sigma884 3:d040fa9b5bb9 171 cmd[buff_ptr + 2] = EEPROM_cast.cast[0];
Sigma884 3:d040fa9b5bb9 172 cmd[buff_ptr + 3] = EEPROM_cast.cast[1];
Sigma884 3:d040fa9b5bb9 173 cmd[buff_ptr + 4] = EEPROM_cast.cast[2];
Sigma884 3:d040fa9b5bb9 174 cmd[buff_ptr + 5] = EEPROM_cast.cast[3];
Sigma884 0:a945081a4a9e 175
Sigma884 0:a945081a4a9e 176 buff_ptr += 4;
Sigma884 0:a945081a4a9e 177 }
Sigma884 0:a945081a4a9e 178 return buff_ptr;
Sigma884 0:a945081a4a9e 179 }
Sigma884 0:a945081a4a9e 180
Sigma884 0:a945081a4a9e 181 int EEPROM_lib::chargeBuff(double DATA){
Sigma884 0:a945081a4a9e 182 if(buff_ptr < 128 - 7){
Sigma884 0:a945081a4a9e 183 EEPROM_cast.d = DATA;
Sigma884 3:d040fa9b5bb9 184 cmd[buff_ptr + 2] = EEPROM_cast.cast[0];
Sigma884 3:d040fa9b5bb9 185 cmd[buff_ptr + 3] = EEPROM_cast.cast[1];
Sigma884 3:d040fa9b5bb9 186 cmd[buff_ptr + 4] = EEPROM_cast.cast[2];
Sigma884 3:d040fa9b5bb9 187 cmd[buff_ptr + 5] = EEPROM_cast.cast[3];
Sigma884 3:d040fa9b5bb9 188 cmd[buff_ptr + 6] = EEPROM_cast.cast[4];
Sigma884 3:d040fa9b5bb9 189 cmd[buff_ptr + 7] = EEPROM_cast.cast[5];
Sigma884 3:d040fa9b5bb9 190 cmd[buff_ptr + 8] = EEPROM_cast.cast[6];
Sigma884 3:d040fa9b5bb9 191 cmd[buff_ptr + 9] = EEPROM_cast.cast[7];
Sigma884 0:a945081a4a9e 192
Sigma884 0:a945081a4a9e 193 buff_ptr += 8;
Sigma884 0:a945081a4a9e 194 }
Sigma884 0:a945081a4a9e 195 return buff_ptr;
Sigma884 0:a945081a4a9e 196 }
Sigma884 0:a945081a4a9e 197
Sigma884 0:a945081a4a9e 198 void EEPROM_lib::writeBuff(){
Sigma884 0:a945081a4a9e 199 for(int i = buff_ptr+2; i < 130; i ++){
Sigma884 0:a945081a4a9e 200 cmd[i] = 0x00;
Sigma884 0:a945081a4a9e 201 }
Sigma884 0:a945081a4a9e 202 i2c -> write(slave, cmd, 130);
Sigma884 0:a945081a4a9e 203 wait_us(EEPROM_WAIT_US);
Sigma884 0:a945081a4a9e 204
Sigma884 0:a945081a4a9e 205 buff_ptr = 0;
Sigma884 0:a945081a4a9e 206 }
Sigma884 0:a945081a4a9e 207
Sigma884 0:a945081a4a9e 208 int EEPROM_lib::setNextPage(){
Sigma884 0:a945081a4a9e 209 if(cmd[1] == 0x00){
Sigma884 0:a945081a4a9e 210 cmd[1] = 0x80;
Sigma884 0:a945081a4a9e 211 ptr[3] = cmd[1];
Sigma884 0:a945081a4a9e 212 }
Sigma884 0:a945081a4a9e 213 else{
Sigma884 0:a945081a4a9e 214 cmd[1] = 0x00;
Sigma884 0:a945081a4a9e 215 ptr[3] = cmd[1];
Sigma884 0:a945081a4a9e 216 if(cmd[0] == 0xFF){
Sigma884 0:a945081a4a9e 217 cmd[0] = 0x00;
Sigma884 0:a945081a4a9e 218 ptr[2] = cmd[0];
Sigma884 0:a945081a4a9e 219 switch(slave){
Sigma884 0:a945081a4a9e 220 case EEPROM_ADDR_00_0:
Sigma884 0:a945081a4a9e 221 slave = EEPROM_ADDR_00_1;
Sigma884 0:a945081a4a9e 222 ptr[0] = 0x00;
Sigma884 0:a945081a4a9e 223 ptr[1] = 0x01;
Sigma884 0:a945081a4a9e 224 break;
Sigma884 0:a945081a4a9e 225
Sigma884 0:a945081a4a9e 226 case EEPROM_ADDR_00_1:
Sigma884 0:a945081a4a9e 227 slave = EEPROM_ADDR_01_0;
Sigma884 0:a945081a4a9e 228 ptr[0] = 0x01;
Sigma884 0:a945081a4a9e 229 ptr[1] = 0x00;
Sigma884 0:a945081a4a9e 230 break;
Sigma884 0:a945081a4a9e 231
Sigma884 0:a945081a4a9e 232 case EEPROM_ADDR_01_0:
Sigma884 0:a945081a4a9e 233 slave = EEPROM_ADDR_01_1;
Sigma884 0:a945081a4a9e 234 ptr[0] = 0x01;
Sigma884 0:a945081a4a9e 235 ptr[1] = 0x01;
Sigma884 0:a945081a4a9e 236 break;
Sigma884 0:a945081a4a9e 237
Sigma884 0:a945081a4a9e 238 case EEPROM_ADDR_01_1:
Sigma884 0:a945081a4a9e 239 slave = EEPROM_ADDR_10_0;
Sigma884 0:a945081a4a9e 240 ptr[0] = 0x02;
Sigma884 0:a945081a4a9e 241 ptr[1] = 0x00;
Sigma884 0:a945081a4a9e 242 break;
Sigma884 0:a945081a4a9e 243
Sigma884 0:a945081a4a9e 244 case EEPROM_ADDR_10_0:
Sigma884 0:a945081a4a9e 245 slave = EEPROM_ADDR_10_1;
Sigma884 0:a945081a4a9e 246 ptr[0] = 0x02;
Sigma884 0:a945081a4a9e 247 ptr[1] = 0x01;
Sigma884 0:a945081a4a9e 248 break;
Sigma884 0:a945081a4a9e 249
Sigma884 0:a945081a4a9e 250 case EEPROM_ADDR_10_1:
Sigma884 0:a945081a4a9e 251 slave = EEPROM_ADDR_11_0;
Sigma884 0:a945081a4a9e 252 ptr[0] = 0x03;
Sigma884 0:a945081a4a9e 253 ptr[1] = 0x00;
Sigma884 0:a945081a4a9e 254 break;
Sigma884 0:a945081a4a9e 255
Sigma884 0:a945081a4a9e 256 case EEPROM_ADDR_11_0:
Sigma884 0:a945081a4a9e 257 slave = EEPROM_ADDR_11_1;
Sigma884 0:a945081a4a9e 258 ptr[0] = 0x03;
Sigma884 0:a945081a4a9e 259 ptr[1] = 0x01;
Sigma884 0:a945081a4a9e 260 break;
Sigma884 0:a945081a4a9e 261
Sigma884 0:a945081a4a9e 262 case EEPROM_ADDR_11_1:
Sigma884 0:a945081a4a9e 263 slave = 0x00;
Sigma884 0:a945081a4a9e 264 ptr[0] = 0x04;
Sigma884 0:a945081a4a9e 265 ptr[1] = 0x00;
Sigma884 0:a945081a4a9e 266 }
Sigma884 0:a945081a4a9e 267 }
Sigma884 0:a945081a4a9e 268 else{
Sigma884 0:a945081a4a9e 269 cmd[0] ++;
Sigma884 0:a945081a4a9e 270 ptr[2] = cmd[0];
Sigma884 0:a945081a4a9e 271 switch(slave){
Sigma884 0:a945081a4a9e 272 case EEPROM_ADDR_00_0:
Sigma884 0:a945081a4a9e 273 ptr[0] = 0x00;
Sigma884 0:a945081a4a9e 274 ptr[1] = 0x00;
Sigma884 0:a945081a4a9e 275 break;
Sigma884 0:a945081a4a9e 276
Sigma884 0:a945081a4a9e 277 case EEPROM_ADDR_00_1:
Sigma884 0:a945081a4a9e 278 ptr[0] = 0x00;
Sigma884 0:a945081a4a9e 279 ptr[1] = 0x01;
Sigma884 0:a945081a4a9e 280 break;
Sigma884 0:a945081a4a9e 281
Sigma884 0:a945081a4a9e 282 case EEPROM_ADDR_01_0:
Sigma884 0:a945081a4a9e 283 ptr[0] = 0x01;
Sigma884 0:a945081a4a9e 284 ptr[1] = 0x00;
Sigma884 0:a945081a4a9e 285 break;
Sigma884 0:a945081a4a9e 286
Sigma884 0:a945081a4a9e 287 case EEPROM_ADDR_01_1:
Sigma884 0:a945081a4a9e 288 ptr[0] = 0x01;
Sigma884 0:a945081a4a9e 289 ptr[1] = 0x01;
Sigma884 0:a945081a4a9e 290 break;
Sigma884 0:a945081a4a9e 291
Sigma884 0:a945081a4a9e 292 case EEPROM_ADDR_10_0:
Sigma884 0:a945081a4a9e 293 ptr[0] = 0x02;
Sigma884 0:a945081a4a9e 294 ptr[1] = 0x00;
Sigma884 0:a945081a4a9e 295 break;
Sigma884 0:a945081a4a9e 296
Sigma884 0:a945081a4a9e 297 case EEPROM_ADDR_10_1:
Sigma884 0:a945081a4a9e 298 ptr[0] = 0x02;
Sigma884 0:a945081a4a9e 299 ptr[1] = 0x01;
Sigma884 0:a945081a4a9e 300 break;
Sigma884 0:a945081a4a9e 301
Sigma884 0:a945081a4a9e 302 case EEPROM_ADDR_11_0:
Sigma884 0:a945081a4a9e 303 ptr[0] = 0x03;
Sigma884 0:a945081a4a9e 304 ptr[1] = 0x00;
Sigma884 0:a945081a4a9e 305 break;
Sigma884 0:a945081a4a9e 306
Sigma884 0:a945081a4a9e 307 case EEPROM_ADDR_11_1:
Sigma884 0:a945081a4a9e 308 ptr[0] = 0x03;
Sigma884 0:a945081a4a9e 309 ptr[1] = 0x01;
Sigma884 0:a945081a4a9e 310 break;
Sigma884 0:a945081a4a9e 311 }
Sigma884 0:a945081a4a9e 312 }
Sigma884 0:a945081a4a9e 313 }
Sigma884 0:a945081a4a9e 314
Sigma884 0:a945081a4a9e 315 switch(max_num){
Sigma884 0:a945081a4a9e 316 case 1:
Sigma884 0:a945081a4a9e 317 if(ptr[0] > 0x00){
Sigma884 0:a945081a4a9e 318 slave = 0x00;
Sigma884 0:a945081a4a9e 319 cmd[0] = 0x00;
Sigma884 0:a945081a4a9e 320 cmd[1] = 0x00;
Sigma884 0:a945081a4a9e 321 ptr[0] = 0x01;
Sigma884 0:a945081a4a9e 322 ptr[1] = 0x00;
Sigma884 0:a945081a4a9e 323 ptr[2] = 0x00;
Sigma884 0:a945081a4a9e 324 ptr[3] = 0x00;
Sigma884 0:a945081a4a9e 325 }
Sigma884 0:a945081a4a9e 326 break;
Sigma884 0:a945081a4a9e 327
Sigma884 0:a945081a4a9e 328 case 2:
Sigma884 0:a945081a4a9e 329 if(ptr[0] > 0x01){
Sigma884 0:a945081a4a9e 330 slave = 0x00;
Sigma884 0:a945081a4a9e 331 cmd[0] = 0x00;
Sigma884 0:a945081a4a9e 332 cmd[1] = 0x00;
Sigma884 0:a945081a4a9e 333 ptr[0] = 0x02;
Sigma884 0:a945081a4a9e 334 ptr[1] = 0x00;
Sigma884 0:a945081a4a9e 335 ptr[2] = 0x00;
Sigma884 0:a945081a4a9e 336 ptr[3] = 0x00;
Sigma884 0:a945081a4a9e 337 }
Sigma884 0:a945081a4a9e 338 break;
Sigma884 0:a945081a4a9e 339
Sigma884 0:a945081a4a9e 340 case 3:
Sigma884 0:a945081a4a9e 341 if(ptr[0] > 0x02){
Sigma884 0:a945081a4a9e 342 slave = 0x00;
Sigma884 0:a945081a4a9e 343 cmd[0] = 0x00;
Sigma884 0:a945081a4a9e 344 cmd[1] = 0x00;
Sigma884 0:a945081a4a9e 345 ptr[0] = 0x03;
Sigma884 0:a945081a4a9e 346 ptr[1] = 0x00;
Sigma884 0:a945081a4a9e 347 ptr[2] = 0x00;
Sigma884 0:a945081a4a9e 348 ptr[3] = 0x00;
Sigma884 0:a945081a4a9e 349 }
Sigma884 0:a945081a4a9e 350 break;
Sigma884 0:a945081a4a9e 351
Sigma884 0:a945081a4a9e 352 case 4:
Sigma884 0:a945081a4a9e 353 if(ptr[0] > 0x03){
Sigma884 0:a945081a4a9e 354 slave = 0x00;
Sigma884 0:a945081a4a9e 355 cmd[0] = 0x00;
Sigma884 0:a945081a4a9e 356 cmd[1] = 0x00;
Sigma884 0:a945081a4a9e 357 ptr[0] = 0x04;
Sigma884 0:a945081a4a9e 358 ptr[1] = 0x00;
Sigma884 0:a945081a4a9e 359 ptr[2] = 0x00;
Sigma884 0:a945081a4a9e 360 ptr[3] = 0x00;
Sigma884 0:a945081a4a9e 361 }
Sigma884 0:a945081a4a9e 362 break;
Sigma884 0:a945081a4a9e 363 }
Sigma884 0:a945081a4a9e 364
Sigma884 0:a945081a4a9e 365 return (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3];
Sigma884 0:a945081a4a9e 366 }
Sigma884 0:a945081a4a9e 367
Sigma884 0:a945081a4a9e 368 char EEPROM_lib::readByte(int num, int block, char ADDR_H, char ADDR_L){
Sigma884 0:a945081a4a9e 369 if(num > max_num){
Sigma884 0:a945081a4a9e 370 return 0x00;
Sigma884 0:a945081a4a9e 371 }
Sigma884 0:a945081a4a9e 372 switch(num){
Sigma884 0:a945081a4a9e 373 case 1:
Sigma884 0:a945081a4a9e 374 slave = EEPROM_ADDR_00_0;
Sigma884 0:a945081a4a9e 375 break;
Sigma884 0:a945081a4a9e 376
Sigma884 0:a945081a4a9e 377 case 2:
Sigma884 0:a945081a4a9e 378 slave = EEPROM_ADDR_01_0;
Sigma884 0:a945081a4a9e 379 break;
Sigma884 0:a945081a4a9e 380
Sigma884 0:a945081a4a9e 381 case 3:
Sigma884 0:a945081a4a9e 382 slave = EEPROM_ADDR_10_0;
Sigma884 0:a945081a4a9e 383 break;
Sigma884 0:a945081a4a9e 384
Sigma884 0:a945081a4a9e 385 case 4:
Sigma884 0:a945081a4a9e 386 slave = EEPROM_ADDR_11_0;
Sigma884 0:a945081a4a9e 387 break;
Sigma884 0:a945081a4a9e 388 }
Sigma884 0:a945081a4a9e 389 if(block == 1){
Sigma884 0:a945081a4a9e 390 slave = slave | 0x08;
Sigma884 0:a945081a4a9e 391 }
Sigma884 0:a945081a4a9e 392 cmd[0] = ADDR_H;
Sigma884 0:a945081a4a9e 393 cmd[1] = ADDR_L;
Sigma884 0:a945081a4a9e 394
Sigma884 0:a945081a4a9e 395 i2c -> write(slave, cmd, 2);
Sigma884 0:a945081a4a9e 396 i2c -> read(slave | 1, cmd, 1);
Sigma884 0:a945081a4a9e 397
Sigma884 0:a945081a4a9e 398 return cmd[0];
Sigma884 0:a945081a4a9e 399 }
Sigma884 0:a945081a4a9e 400
Sigma884 0:a945081a4a9e 401 void EEPROM_lib::readMultiByte(int num, int block, char ADDR_H, char ADDR_L, char *DATA, int size){
Sigma884 0:a945081a4a9e 402 if(num > max_num){
Sigma884 0:a945081a4a9e 403 return;
Sigma884 0:a945081a4a9e 404 }
Sigma884 0:a945081a4a9e 405 switch(num){
Sigma884 0:a945081a4a9e 406 case 1:
Sigma884 0:a945081a4a9e 407 slave = EEPROM_ADDR_00_0;
Sigma884 0:a945081a4a9e 408 break;
Sigma884 0:a945081a4a9e 409
Sigma884 0:a945081a4a9e 410 case 2:
Sigma884 0:a945081a4a9e 411 slave = EEPROM_ADDR_01_0;
Sigma884 0:a945081a4a9e 412 break;
Sigma884 0:a945081a4a9e 413
Sigma884 0:a945081a4a9e 414 case 3:
Sigma884 0:a945081a4a9e 415 slave = EEPROM_ADDR_10_0;
Sigma884 0:a945081a4a9e 416 break;
Sigma884 0:a945081a4a9e 417
Sigma884 0:a945081a4a9e 418 case 4:
Sigma884 0:a945081a4a9e 419 slave = EEPROM_ADDR_11_0;
Sigma884 0:a945081a4a9e 420 break;
Sigma884 0:a945081a4a9e 421 }
Sigma884 0:a945081a4a9e 422 if(block == 1){
Sigma884 0:a945081a4a9e 423 slave = slave | 0x08;
Sigma884 0:a945081a4a9e 424 }
Sigma884 0:a945081a4a9e 425 cmd[0] = ADDR_H;
Sigma884 0:a945081a4a9e 426 cmd[1] = ADDR_L;
Sigma884 0:a945081a4a9e 427
Sigma884 0:a945081a4a9e 428 i2c -> write(slave, cmd, 2);
Sigma884 0:a945081a4a9e 429 i2c -> read(slave | 1, DATA, size);
Sigma884 0:a945081a4a9e 430 }