Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: ds18b20.cpp
- Revision:
- 4:e076884ef8bd
- Child:
- 5:6226f3c566ef
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ds18b20.cpp Tue May 03 09:23:26 2016 +0000
@@ -0,0 +1,58 @@
+#include "mbed.h"
+#include "1-wire.h"
+#include "log.h"
+#include "io.h"
+#include "wifi.h"
+
+static Ticker ticker;
+#define SEND_BUFFER_LENGTH 2
+#define RECV_BUFFER_LENGTH 10
+static char send[SEND_BUFFER_LENGTH];
+static char recv[RECV_BUFFER_LENGTH];
+static int sendlen = 0;
+static int recvlen = 0;
+
+void DS18B20ReadRom()
+{
+ sendlen = 1;
+ send[0] = 0x33;
+ recvlen = 8;
+ OneWireExchange(sendlen, recvlen, send, recv, 0);
+}
+void DS18B20ReadScratchpad()
+{
+ sendlen = 2;
+ send[0] = 0xCC;
+ send[1] = 0xBE;
+ recvlen = 9;
+ OneWireExchange(sendlen, recvlen, send, recv, 0);
+}
+void DS18B20ConvertT()
+{
+ sendlen = 2;
+ send[0] = 0xCC;
+ send[1] = 0x44;
+ recvlen = 0;
+ OneWireExchange(sendlen, recvlen, send, recv, 750);
+}
+int DS18B20Init()
+{
+ ticker.attach(&DS18B20ReadScratchpad, 10.0);
+ return 0;
+}
+int DS18B20Main()
+{
+ static int wasbusy = false;
+
+ if (!OneWireBusy() && wasbusy)
+ {
+ LogF("1-wire | send:");
+ for (int i = 0; i < sendlen; i++) LogF(" %02x", send[i]);
+ LogF(" | recv:");
+ for (int i = 0; i < recvlen; i++) LogF(" %02x", recv[i]);
+ LogF("\r\n");
+ }
+
+ wasbusy = OneWireBusy();
+ return 0;
+}
\ No newline at end of file