Diff: OneWireEEPROM.cpp
- Revision:
- 2:193926923cb0
- Parent:
- 1:7218c076189b
--- a/OneWireEEPROM.cpp Sun Apr 17 17:26:52 2011 +0000
+++ b/OneWireEEPROM.cpp Tue Jan 17 08:30:45 2012 +0000
@@ -54,6 +54,8 @@
for (int i = 0; i < ADDRESS_SIZE; i++)
_ROMCode[i]=0;
}
+
+ active=0;
}
@@ -135,7 +137,7 @@
} else {
output.printf("OneWireEEPROM present and correct.\r\n");
}
-
+ active=1;
return true;
}
@@ -241,7 +243,7 @@
oneWire.writeByte(_TA1);
oneWire.writeByte(_TA2);
- output.printf ("\r\nReading... TA1=%X TA2=%X",_TA1, _TA2);
+ // output.printf ("\r\nReading... TA1=%X TA2=%X",_TA1, _TA2);
for (memPtr = 0; memPtr < Size; memPtr++) {
tmpReader = oneWire.readByte();
@@ -253,7 +255,7 @@
Destination[memPtr] = tmpReader;
}
- output.printf ("-> %i byte(s)\r\n",memPtr);
+ // output.printf ("-> %i byte(s)\r\n",memPtr);
return memPtr;
} else {
@@ -307,14 +309,80 @@
}
bool OneWireEEPROM::WriteWord(uint16_t v, uint16_t Address) {
+ bool ok=false;
+ int it=0;
uint8_t Mem[2];
Mem[0]=(uint8_t)(v & 0x00FF);
Mem[1]=(uint8_t)((v & 0xFF00)>>8);
- return WriteMemory(Mem,Address,2);
+
+ do {
+ ok=WriteMemory(Mem,Address,2);
+ it++;
+ } while ((ok==false) && (it<5));
+ if (it>1) {
+ output.printf (" EEPROM WriteWord %i times ->",it);
+ if (ok)
+ output.printf("ok\r\n");
+ else
+ output.printf("not ok\r\n");
+ }
+ return ok;
}
bool OneWireEEPROM::WriteByte(uint8_t b, uint16_t Address) {
+ bool ok=false;
+ int it=0;
uint8_t Mem[1];
Mem[0]=(uint8_t)(b & 0x00FF);
- return WriteMemory(Mem,Address,1);
+ do {
+ ok=WriteMemory(Mem,Address,1);
+ it++;
+ } while ((ok==false) && (it<5));
+ if (it>1) {
+ output.printf (" EEPROM WriteByte %i times ->",it);
+ if (ok)
+ output.printf("ok\r\n");
+ else
+ output.printf("not ok\r\n");
+ }
+ return ok;
+}
+
+uint16_t OneWireEEPROM::ReadWord(uint16_t Address) {
+ int size;
+ int it=0;
+
+ uint8_t Mem[2];
+ do {
+ size=ReadMemory(Mem,Address,2);
+ it++;
+ } while ((size==0) && (it<5));
+// output.printf ("%i %i \r\n",Mem[0],Mem[1]);
+ if (it>1) {
+ output.printf (" EEPROM ReadWord %i times ->",it);
+ if (size>0)
+ output.printf("ok\r\n");
+ else
+ output.printf("not ok\r\n");
+ }
+ return (uint16_t)Mem[0] + (uint16_t) (Mem[1]<<8);
+}
+
+uint8_t OneWireEEPROM::ReadByte(uint8_t Address) {
+ int size;
+ int it=0;
+ uint8_t Mem[1];
+ do {
+ size=ReadMemory(Mem,Address,1);
+ it++;
+ } while ((size==0) && (it<5));
+ // output.printf ("%i \r\n",Mem[0]);
+ if (it>1) {
+ output.printf (" EEPROM ReadByte %i times ->",it);
+ if (size>0)
+ output.printf("ok\r\n");
+ else
+ output.printf("not ok\r\n");
+ }
+ return (uint8_t) Mem[0];
}
\ No newline at end of file