OneWire Library
The OneWire library provides routines for communication via the Dallas OneWire protocol, e.g. with DS18x20 digital thermometer. OneWire is a Master/Slave protocol, and all communication cabling required is a single wire. OneWire enabled devices should have open collector drivers (with single pull-up resistor) on the shared data line.
Slave devices on the OneWire bus can even get their power supply from data line. For detailed schematic see device datasheet.
Some basic characteristics of this protocol are:
- single master system,
- low cost,
- low transfer rates (up to 16 kbps),
- fairly long distances (up to 300 meters),
- small data transfer packages.
Each OneWire device also has a unique 64-bit registration number (8-bit device type, 48-bit serial number and 8-bit CRC), so multiple slaves can co-exist on the same bus.

- Oscillator frequency Fosc needs to be at least 4MHz in order to use the routines with Dallas digital thermometers.
- This library implements time-based activities, so interrupts need to be disabled when using OneWire library.
Library Routines
Ow_Reset
Prototype |
sub function Ow_Reset(dim byref port as longword, dim pin as byte) as longword |
---|---|
Description |
Issues OneWire reset signal for DS18x20. |
Parameters |
|
Returns |
|
Requires |
Devices compliant with the Dallas OneWire protocol. |
Example |
Stellaris' Issue Reset signal on One-Wire Bus connected to pin GPIO_PORTF.B6 Ow_Reset(GPIO_PORTF, 6) STM32' Issue Reset signal on One-Wire Bus connected to pin GPIOB_ODR.B10 Ow_Reset(GPIOB_ODR, 10) |
Notes |
None. |
Ow_Read
Prototype |
sub function Ow_Read(dim byref port as longword, dim pin as byte) as byte |
---|---|
Description |
Reads one byte of data via the OneWire bus. |
Parameters |
|
Returns |
Data read from an external device over the OneWire bus. |
Requires |
Devices compliant with the Dallas OneWire protocol. |
Example |
Stellaris' Read a byte from the One-Wire Bus connected to pin GPIO_PORTF.B6 dim read_data as byte ... read_data = Ow_Read(GPIO_PORTF, 6) STM32' Read a byte from the One-Wire Bus connected to pin GPIOB_ODR.10 dim read_data as byte ... read_data = Ow_Read(GPIOB_ODR, 10) |
Notes |
None. |
Ow_Write
Prototype |
sub procedure Ow_Write(dim byref port as longword, dim pin, data_ as byte) |
---|---|
Description |
Writes one byte of data via the OneWire bus. |
Parameters |
|
Returns |
Nothing. |
Requires |
Devices compliant with the Dallas OneWire protocol. |
Example |
Stellaris' Send a byte to the One-Wire Bus connected to pin GPIO_PORTF.B6 Ow_Write(GPIO_PORTF, 6, 0xCC) STM32' Send a byte to the One-Wire Bus connected to pin GPIOB_ODR.10 Ow_Write(GPIOB_ODR, 10, 0xCC) |
Notes |
None. |
What do you think about this topic ? Send us feedback!