ibutton function for mbed working!

Dependencies:   OneWire mbed

Fork of ibutton by Stijn Sontrop

Files at this revision

API Documentation at this revision

Comitter:
Renato
Date:
Tue Aug 27 16:20:09 2013 +0000
Parent:
0:39cce56e485b
Commit message:
ibutton function working!

Changed in this revision

OneWire.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 39cce56e485b -r d6732fa1e5f8 OneWire.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OneWire.lib	Tue Aug 27 16:20:09 2013 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/fblanc/code/OneWire/#8c4e1841eb30
diff -r 39cce56e485b -r d6732fa1e5f8 main.cpp
--- a/main.cpp	Sat Feb 12 11:00:05 2011 +0000
+++ b/main.cpp	Tue Aug 27 16:20:09 2013 +0000
@@ -1,9 +1,10 @@
 #include "mbed.h"
-#define ibuttonpin p20
+//#define ibuttonpin p21
 
 Serial pc(USBTX, USBRX);
 
-DigitalInOut ibuttondata(ibuttonpin);
+//DigitalInOut ibuttondata(ibuttonpin);
+DigitalInOut sensor(p21);
 
 typedef struct {
     unsigned char family;
@@ -26,25 +27,25 @@
 }
 
 void OneWireReset(void) { //Generates reset on 1-wire bus
-    ibuttondata.output();
-    ibuttondata = 0;
+    sensor.output();
+    sensor = 0;
     wait_us(500);
-    ibuttondata.input();
+    sensor.input();
     wait_us(500);
 }
 
 void OneWireOutByte(unsigned char data) { //Write byte on 1-wire bus
     for (int n = 8;n!=0; n--) {
         if ((data & 0x01) == 1) {
-            ibuttondata.output();
-            ibuttondata = 0;
+            sensor.output();
+            sensor = 0;
             wait_us(5);
-            ibuttondata.input();
+            sensor.input();
             wait_us(60);
         } else {
-            ibuttondata.output();
+            sensor.output();
             wait_us(60);
-            ibuttondata.input();
+            sensor.input();
         }
         data = data >> 1;
     }
@@ -54,12 +55,12 @@
     unsigned char d = 0;
     unsigned char b;
     for (int n = 0; n<8; n++) {
-        ibuttondata.output();
-        ibuttondata = 0;
+        sensor.output();
+        sensor = 0;
         wait_us(5);
-        ibuttondata.input();
+        sensor.input();
         wait_us(5);
-        b = ibuttondata;
+        b = sensor;
         wait_us(50);
         d = (d >> 1) | (b << 7);
     }
@@ -87,16 +88,25 @@
     }
     return detect;
 }
+
+//LocalFileSystem local("local");
+
 int main() {
-    ibuttonvalue detected;    
+
+//FILE *fp = fopen("/local/out.txt", "rw");
+
+    ibuttonvalue detected; 
+    int i;   
     while(1) {
         detected = DetectiButton();
         if (detected.valid == 1) { //Test valid flag
             pc.printf("iButton Family: %X Serial: ", detected.family);
-            for (int i = 0; i < 6; i++) {
+            for (i=6-1; i>=0; i--) {
                 pc.printf("%X", detected.serial[i]);
+               // fprintf(fp, "Serial: %X", detected.serial[i]);
+               
             }
             pc.printf(" CRC: %X\n", detected.crc);
-        }
+       }//fclose(fp);
     }
 }