-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for hardware (DS2482) based OWI bus manager
- Loading branch information
1 parent
a732841
commit 1b4e7c1
Showing
12 changed files
with
741 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,32 @@ | ||
# Arduino-OWI | ||
The OWI library has been developed to support the implementation of | ||
1-wire device drivers. The library includes an example device driver | ||
and a bus scanner. | ||
1-wire bus managers and device drivers. The library includes a GPIO | ||
based software and DS2482 based hardware bus manager, and device | ||
driver for DS18B20. | ||
|
||
Version: 1.5 | ||
The examples directory contains device search, bus scanner, | ||
thermometer alarm search, and example sketches for DS18B20, DS1990A | ||
and DS2482. | ||
|
||
Version: 1.6 | ||
|
||
## Classes | ||
|
||
* [Abstract One-Wire Bus Manager and Device Interface, OWI](./src/OWI.h) | ||
* [Software One-Wire Interface, Software::OWI](./src/Software/OWI.h) | ||
* [Software One-Wire Bus Manager, GPIO, Software::OWI](./src/Software/OWI.h) | ||
* [Hardware One-Wire Bus Manager, DS2482, Hardware::OWI](./src/Hardware/OWI.h) | ||
* [Programmable Resolution 1-Wire Digital Thermometer, DS18B20](./src/Driver/DS18B20.h) | ||
|
||
## Example Sketches | ||
|
||
* [DS18B20](./examples/DS18B20) | ||
* [DS1990A](./examples/DS1990A) | ||
* [DS2482](./examples/DS2482) | ||
* [Alarm](./examples/Alarm) | ||
* [Scanner](./examples/Scanner) | ||
* [Search](./examples/Search) | ||
* [Alarm](./examples/Alarm) | ||
|
||
## Dependencies | ||
|
||
* [Arduino-GPIO](https://github.com/mikaelpatel/Arduino-GPIO) | ||
* [Arduino-TWI](https://github.com/mikaelpatel/Arduino-TWI) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
#include "GPIO.h" | ||
#include "OWI.h" | ||
#include "TWI.h" | ||
#include "Hardware/OWI.h" | ||
#include <util/crc16.h> | ||
|
||
#define USE_SOFTWARE_TWI | ||
#if defined(USE_SOFTWARE_TWI) | ||
#include "Software/TWI.h" | ||
Software::TWI<BOARD::D18,BOARD::D19> twi; | ||
#else | ||
#include "Hardware/TWI.h" | ||
Hardware::TWI twi; | ||
#endif | ||
|
||
Hardware::OWI owi(twi); | ||
|
||
// DS18B20 Commands | ||
enum { | ||
CONVERT_T = 0x44, | ||
READ_SCRATCHPAD = 0xbe | ||
}; | ||
|
||
// DS18B20 Scratchpad Memory | ||
struct scratchpad_t { | ||
int16_t temperature; | ||
int8_t high_trigger; | ||
int8_t low_trigger; | ||
uint8_t configuration; | ||
uint8_t reserved[3]; | ||
uint8_t crc; | ||
}; | ||
|
||
#define TRACE(expr) \ | ||
do { \ | ||
Serial.print(#expr "="); \ | ||
Serial.println(expr); \ | ||
} while (0) | ||
|
||
void setup() | ||
{ | ||
Serial.begin(57600); | ||
while (!Serial); | ||
|
||
TRACE(owi.device_reset()); | ||
TRACE(owi.device_config()); | ||
TRACE(owi.set_read_pointer(owi.READ_DATA_REGISTER)); | ||
TRACE(owi.set_read_pointer(owi.CONFIGURATION_REGISTER)); | ||
TRACE(owi.set_read_pointer(owi.CHANNEL_SELECTION_REGISTER)); | ||
TRACE(owi.set_read_pointer(owi.STATUS_REGISTER)); | ||
|
||
uint8_t rom[owi.ROM_MAX] = { 0 }; | ||
uint8_t crc = 0; | ||
TRACE(owi.reset()); | ||
Serial.print(F("rom=")); | ||
owi.write(owi.READ_ROM); | ||
for (size_t i = 0; i < sizeof(rom); i++) { | ||
rom[i] = owi.read(8); | ||
if (rom[i] < 0x10) Serial.print(0); | ||
Serial.print(rom[i], HEX); | ||
crc = _crc_ibutton_update(crc, rom[i]); | ||
} | ||
Serial.print(F(", crc=")); | ||
Serial.println(crc); | ||
|
||
uint8_t value = 0; | ||
uint8_t bits = 0; | ||
uint8_t ix = 0; | ||
uint8_t res = 0; | ||
uint8_t dir = 0; | ||
bool id; | ||
bool nid; | ||
crc = 0; | ||
TRACE(owi.reset()); | ||
Serial.print(F("rom=")); | ||
owi.write(owi.SEARCH_ROM); | ||
do { | ||
res = owi.triplet(dir); | ||
id = (res & 1) != 0; | ||
nid = (res & 2) != 0; | ||
value = (value >> 1); | ||
if (dir) value |= 0x80; | ||
bits += 1; | ||
if (bits == CHARBITS) { | ||
rom[ix] = value; | ||
if (rom[ix] < 0x10) Serial.print(0); | ||
Serial.print(rom[ix], HEX); | ||
crc = _crc_ibutton_update(crc, rom[ix]); | ||
ix += 1; | ||
bits = 0; | ||
value = 0; | ||
} | ||
} while (id != nid); | ||
Serial.print(F(", crc=")); | ||
Serial.println(crc); | ||
} | ||
|
||
void loop() | ||
{ | ||
owi.reset(); | ||
owi.write(owi.SKIP_ROM); | ||
owi.write(CONVERT_T); | ||
delay(750); | ||
|
||
owi.reset(); | ||
owi.write(owi.SKIP_ROM); | ||
owi.write(READ_SCRATCHPAD); | ||
|
||
scratchpad_t scratchpad; | ||
uint8_t* p = (uint8_t*) &scratchpad; | ||
uint8_t crc = 0; | ||
for (size_t i = 0; i < sizeof(scratchpad); i++) { | ||
p[i] = owi.read(); | ||
crc = _crc_ibutton_update(crc, p[i]); | ||
} | ||
if (crc == 0) { | ||
float temperature = scratchpad.temperature * 0.0625; | ||
TRACE(temperature); | ||
} else | ||
TRACE(crc); | ||
delay(2000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
name=Arduino-OWI | ||
version=1.5 | ||
version=1.6 | ||
author=Mikael Patel | ||
maintainer=Mikael Patel <[email protected]> | ||
sentence=One-Wire Interface (OWI) library for Arduino. | ||
paragraph=The OWI library has been developed to support the implementation of 1-wire device drivers. Includes abstract OWI bus manager class, GPIO based Software::OWI bus manager and device driver for DS18B20. | ||
paragraph=The OWI library has been developed to support the implementation of 1-wire device drivers. Includes abstract OWI bus manager class, GPIO based Software::OWI bus manager, DS2482 based Hardware::OWI bus manager, and device driver for DS18B20. | ||
category=Communication | ||
url=https://github.com/mikaelpatel/Arduino-OWI | ||
architectures=avr,sam |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.