1W-EEPROM testprogram

Dependencies:   mbed OneWireEEPROM

Committer:
Wimpie
Date:
Tue Jan 17 08:47:59 2012 +0000
Revision:
0:be7c899f5c81

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wimpie 0:be7c899f5c81 1 /*
Wimpie 0:be7c899f5c81 2 * OneWireEEPROM testprogram
Wimpie 0:be7c899f5c81 3 *
Wimpie 0:be7c899f5c81 4 * DS2433
Wimpie 0:be7c899f5c81 5 * DS28EC20
Wimpie 0:be7c899f5c81 6 *
Wimpie 0:be7c899f5c81 7 * Copyright (C) <2011> Wim De Roeve <wim312@gmail.com>
Wimpie 0:be7c899f5c81 8 *
Wimpie 0:be7c899f5c81 9 * OneWireEEPROM is free software: you can redistribute it and/or modify
Wimpie 0:be7c899f5c81 10 * it under the terms of the GNU General Public License as published by
Wimpie 0:be7c899f5c81 11 * the Free Software Foundation, either version 3 of the License, or
Wimpie 0:be7c899f5c81 12 * (at your option) any later version.
Wimpie 0:be7c899f5c81 13 *
Wimpie 0:be7c899f5c81 14 * OneWireEEPROM is distributed in the hope that it will be useful,
Wimpie 0:be7c899f5c81 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Wimpie 0:be7c899f5c81 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Wimpie 0:be7c899f5c81 17 * GNU General Public License for more details.
Wimpie 0:be7c899f5c81 18 *
Wimpie 0:be7c899f5c81 19 * You should have received a copy of the GNU General Public License
Wimpie 0:be7c899f5c81 20 * If not, see <http://www.gnu.org/licenses/>.
Wimpie 0:be7c899f5c81 21 */
Wimpie 0:be7c899f5c81 22
Wimpie 0:be7c899f5c81 23 #include "mbed.h"
Wimpie 0:be7c899f5c81 24 #include "OneWireEEPROM.h"
Wimpie 0:be7c899f5c81 25
Wimpie 0:be7c899f5c81 26 Serial output1(USBTX, USBRX);
Wimpie 0:be7c899f5c81 27
Wimpie 0:be7c899f5c81 28 // EEPROM memorypointers
Wimpie 0:be7c899f5c81 29 #define MEM1 0
Wimpie 0:be7c899f5c81 30 #define MEM2 MEM1+2
Wimpie 0:be7c899f5c81 31 #define MEM3 MEM2+2
Wimpie 0:be7c899f5c81 32 #define MEM4 MEM3+1
Wimpie 0:be7c899f5c81 33
Wimpie 0:be7c899f5c81 34 // unique 1-wire serialkey
Wimpie 0:be7c899f5c81 35 // fill RCE1 with you 1 wire serialkey
Wimpie 0:be7c899f5c81 36
Wimpie 0:be7c899f5c81 37 unsigned char RCE1[8]={0x43,0x8D,0x00,0x00,0x00,0x00,0x00,0x00};
Wimpie 0:be7c899f5c81 38
Wimpie 0:be7c899f5c81 39 // device(mbed pin, crcOn, useAddress, parasitic, type ,ROM code)
Wimpie 0:be7c899f5c81 40 OneWireEEPROM EEPROM1(p21 , false, true, false ,DS2433 ,RCE1);
Wimpie 0:be7c899f5c81 41
Wimpie 0:be7c899f5c81 42 void init_EEPROM() {
Wimpie 0:be7c899f5c81 43
Wimpie 0:be7c899f5c81 44 int it=0;
Wimpie 0:be7c899f5c81 45 bool ok=false;
Wimpie 0:be7c899f5c81 46
Wimpie 0:be7c899f5c81 47 do {
Wimpie 0:be7c899f5c81 48 it++;
Wimpie 0:be7c899f5c81 49 ok=EEPROM1.Initialize();
Wimpie 0:be7c899f5c81 50 } while ((it<3) and (!ok));
Wimpie 0:be7c899f5c81 51
Wimpie 0:be7c899f5c81 52 }
Wimpie 0:be7c899f5c81 53
Wimpie 0:be7c899f5c81 54 int main() {
Wimpie 0:be7c899f5c81 55
Wimpie 0:be7c899f5c81 56 uint8_t b1=10;
Wimpie 0:be7c899f5c81 57 uint8_t b2=255;
Wimpie 0:be7c899f5c81 58 int16_t w1=16000;
Wimpie 0:be7c899f5c81 59 int16_t w2=9876;
Wimpie 0:be7c899f5c81 60
Wimpie 0:be7c899f5c81 61 init_EEPROM();
Wimpie 0:be7c899f5c81 62
Wimpie 0:be7c899f5c81 63 output1.printf("\r\n b1=%d, b2=%d, w1=%d, w2=%d",b1,b2,w1,w2);
Wimpie 0:be7c899f5c81 64
Wimpie 0:be7c899f5c81 65 if (EEPROM1.active) {
Wimpie 0:be7c899f5c81 66 output1.printf("\r\n writing to EEPROM...");
Wimpie 0:be7c899f5c81 67 EEPROM1.WriteWord(w1 ,MEM1); // w1 is 2 bytes
Wimpie 0:be7c899f5c81 68 EEPROM1.WriteWord(w2 ,MEM2); // w2 is 2 bytes
Wimpie 0:be7c899f5c81 69 EEPROM1.WriteByte(b1 ,MEM3); // b1 is 1 byte
Wimpie 0:be7c899f5c81 70 EEPROM1.WriteByte(b2 ,MEM4); // b2 is 1 byte
Wimpie 0:be7c899f5c81 71 }
Wimpie 0:be7c899f5c81 72
Wimpie 0:be7c899f5c81 73 b1=0;
Wimpie 0:be7c899f5c81 74 b2=0;
Wimpie 0:be7c899f5c81 75 w1=0;
Wimpie 0:be7c899f5c81 76 w2=0;
Wimpie 0:be7c899f5c81 77
Wimpie 0:be7c899f5c81 78 output1.printf("\r\n clearing values...");
Wimpie 0:be7c899f5c81 79 output1.printf("\r\n b1=%d, b2=%d, w1=%d, w2=%d",b1,b2,w1,w2);
Wimpie 0:be7c899f5c81 80
Wimpie 0:be7c899f5c81 81 if (EEPROM1.active) {
Wimpie 0:be7c899f5c81 82 output1.printf("\r\n reading from EEPROM...");
Wimpie 0:be7c899f5c81 83 w1=EEPROM1.ReadWord(MEM1);
Wimpie 0:be7c899f5c81 84 w2=EEPROM1.ReadWord(MEM2);
Wimpie 0:be7c899f5c81 85 b1=EEPROM1.ReadWord(MEM3);
Wimpie 0:be7c899f5c81 86 b2=EEPROM1.ReadWord(MEM4);
Wimpie 0:be7c899f5c81 87 }
Wimpie 0:be7c899f5c81 88
Wimpie 0:be7c899f5c81 89 output1.printf("\r\n b1=%d, b2=%d, w1=%d, w2=%d",b1,b2,w1,w2);
Wimpie 0:be7c899f5c81 90 }