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:

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.

  Important :

Library Routines

Ow_Reset

Prototype

unsigned int Ow_Reset(unsigned int *port, unsigned int pin);

Description

Issues OneWire reset signal for DS18x20.

Parameters
  • port: OneWire bus port
  • pin: OneWire bus pin
Returns

  • 0 if the device is present
  • 1 if the device is not present

Requires

Devices compliant with the Dallas OneWire protocol.

Example

Stellaris

// Issue Reset signal on One-Wire Bus connected to pin RF6
Ow_Reset(&GPIO_PORTF,6);

MSP432

// Issue Reset signal on One-Wire Bus connected to pin DIO_P6OUT.B6
Ow_Reset(&DIO_P6OUT,6);

STM32

// Issue Reset signal on One-Wire Bus connected to pin GPIOB_ODR.B10
Ow_Reset(&GPIOB_ODR, 10);

CEC1x02

// Issue Reset signal on One-Wire Bus
Ow_Reset(&GPIO_PORT_130_137, 6);
    
Notes

None.

Ow_Read

Prototype

unsigned short Ow_Read(unsigned int *port, unsigned int pin);

Description

Reads one byte of data via the OneWire bus.

Parameters
  • port: OneWire bus port
  • pin: OneWire bus pin
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
unsigned short read_data;
...
read_data = Ow_Read(&GPIO_PORTF, 6);

MSP432

// Read a byte from the One-Wire Bus connected to pin DIO_P6OUT.B6
unsigned short read_data;
...
read_data = Ow_Read(&DIO_P6OUT, 6);

STM32

// Read a byte from the One-Wire Bus connected to pin GPIOB_ODR.B10
unsigned short read_data;
...
read_data = Ow_Read(&GPIOB_ODR, 10);

CEC1x02

// Read a byte from the One-Wire Bus
unsigned short read_data;
...
read_data = Ow_Read(&GPIO_PORT_130_137, 6);
Notes

None.

Ow_Write

Prototype

void Ow_Write(unsigned int *port, unsigned int pin, unsigned short data_);

Description

Writes one byte of data via the OneWire bus.

Parameters
  • port: OneWire bus port
  • pin: OneWire bus pin
  • data_: data to be written
Returns

Nothing.

Requires

Devices compliant with the Dallas OneWire protocol.

Example

Stellaris

// Send a byte to the One-Wire Bus connected to pin GPIO_PORTE.B6
Ow_Write(&GPIO_PORTF, 6, 0xCC);

MSP432

// Send a byte to the One-Wire Bus connected to pin DIO_P6OUT.B6
Ow_Write(&DIO_P6OUT, 6, 0xCC);

STM32

// Send a byte to the One-Wire Bus connected to pin GGPIOB_ODR.B10
Ow_Write(&GGPIOB_ODR, 10, 0xCC);

CEC1x02

// Send a byte to the One-Wire Bus
Ow_Write(&GPIO_PORT_130_137, 6);
Notes

None.

Copyright (c) 2002-2019 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code