Revision 2:193926923cb0, committed 2012-01-17
- Comitter:
- Wimpie
- Date:
- Tue Jan 17 08:30:45 2012 +0000
- Parent:
- 1:7218c076189b
- Commit message:
- readbyte readword
Changed in this revision
diff -r 7218c076189b -r 193926923cb0 OneWireCRC.cpp
--- a/OneWireCRC.cpp Sun Apr 17 17:26:52 2011 +0000
+++ b/OneWireCRC.cpp Tue Jan 17 08:30:45 2012 +0000
@@ -102,7 +102,11 @@
//--------------------------------------------------------------------------
#include "OneWireCRC.h"
-#include "OneWireDefs.h"
+
+// ROM commands
+#define OVERDRIVE_SKIP 0x3C
+#define MATCH_ROM 0x55
+#define SKIP_ROM 0xCC
// recommended data sheet timings in micro seconds
const int standardT[] = {6, 64, 60, 10, 9, 55, 0, 480, 70, 410};
diff -r 7218c076189b -r 193926923cb0 OneWireEEPROM.cpp
--- 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
diff -r 7218c076189b -r 193926923cb0 OneWireEEPROM.h
--- a/OneWireEEPROM.h Sun Apr 17 17:26:52 2011 +0000
+++ b/OneWireEEPROM.h Tue Jan 17 08:30:45 2012 +0000
@@ -44,6 +44,8 @@
#define COPYSCRATCHPAD 0x55
#define READMEMORY 0xF0
+
+
#define PAGESIZE 0x20 // 32 bytes for each page
#define DS2433PAGES 0x10 // 16 pages
#define DS28EC20PAGES 0x50 // 80 pages
@@ -79,6 +81,9 @@
bool WriteMemory(uint8_t* Source, uint16_t Address, uint8_t Size);
bool WriteWord(uint16_t v,uint16_t Address);
bool WriteByte(uint8_t b,uint16_t Address);
+
+ uint16_t ReadWord(uint16_t Address);
+ uint8_t ReadByte(uint8_t Address);
//
int ReadMemory(uint8_t* Destination, uint16_t Address, uint16_t Size);
void ShowMemory(int PageFrom, int PageTo);