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.
ds18b20.cpp
- Committer:
- andrewboyson
- Date:
- 2016-05-03
- Revision:
- 4:e076884ef8bd
- Child:
- 5:6226f3c566ef
File content as of revision 4:e076884ef8bd:
#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;
}