Contiki 3.x
Functions
onewire.h File Reference

    One wire driver using hardware UART as a bus master.
More...

#include <stdint.h>

Go to the source code of this file.

Functions

void ow_init (void)
 Initialize the 1-wire driver. More...
 
void ow_reset (void)
 Reset the 1-wire bus. More...
 
void ow_write_bytes (const uint8_t *src, const uint8_t count)
 Write a sequence of bytes to the 1-wire bus. More...
 
void ow_write_byte (const uint8_t data)
 Shorthand function to write a single byte to the 1-wire bus. More...
 
void ow_read_bytes (uint8_t *dest, const uint8_t count)
 Read a sequence of bytes from the 1-wire bus. More...
 
uint8_t ow_compute_crc (const uint8_t *data, const uint8_t count)
 Compute a 1-wire 8-bit CRC. More...
 
ow_rom_code_t ow_read_rom (void)
 Issue a 1-wire READ ROM command. More...
 
void ow_skip_rom (void)
 Issue a 1-wire SKIP ROM command. More...
 
void ow_match_rom (const ow_rom_code_t id)
 Issue a 1-wire MATCH ROM command. More...
 
void ow_skip_or_match_rom (const ow_rom_code_t id)
 Shorthand function for MATCH ROM or SKIP ROM if id is zero. More...
 

Detailed Description

    One wire driver using hardware UART as a bus master.
Author
Joakim Gebart joaki.nosp@m.m.ge.nosp@m.bart@.nosp@m.eist.nosp@m.ec.se
Note
This is heavily based on Maxim document TUTORIAL 214 "Using a UART to Implement a 1-Wire Bus Master"

Definition in file onewire.h.

Function Documentation

uint8_t ow_compute_crc ( const uint8_t *  data,
const uint8_t  count 
)

Compute a 1-wire 8-bit CRC.

This function uses a lookup table method of computing the CRC one byte at a time, instead of bit per bit. The table is found in ow_crc_table in onewire-crc-table.h.

The polynomial used by the 1-wire bus is x^8 + x^5 + x^4 + x^0, or 0x31. But take care when computing the CRC (or producing a lookup table) that the CRC is computed LSB first and using the reversed polynomial 0x8C instead.

Note
Because of the mathematics of the CRC, if passed a message where the last byte is the CRC, the return value will be 0 if the CRC is correct for the message.
Parameters
dataThe message.
countNumber of bytes in the message.
Returns
The CRC

Definition at line 401 of file onewire.c.

Referenced by ds18b20_read_scratchpad(), and ow_read_rom().

void ow_init ( void  )

Initialize the 1-wire driver.

This will set up the clocks, interrupts and I/O pins.

Definition at line 220 of file onewire.c.

References NVIC_EnableIRQ(), SIM, and uart_module_enable().

void ow_match_rom ( const ow_rom_code_t  id)

Issue a 1-wire MATCH ROM command.

The MATCH ROM command is used to single out a specific device using its ROM code as identifier.

Parameters
idThe ROM code of the selected device.

Definition at line 482 of file onewire.c.

References ow_reset(), and ow_write_bytes().

Referenced by ow_skip_or_match_rom().

void ow_read_bytes ( uint8_t *  dest,
const uint8_t  count 
)

Read a sequence of bytes from the 1-wire bus.

Contrary to the ow_write_bytes function, this function is synchronous and will do a busy wait until all bits have been read. This is not really desirable but is so only because of laziness and lack of time.

Parameters
destthe destination buffer.
countnumber of bytes to read from the bus.
Todo:
sleep while waiting for rx bits on 1-wire bus.

Definition at line 365 of file onewire.c.

Referenced by ds18b20_read_scratchpad(), and ow_read_rom().

ow_rom_code_t ow_read_rom ( void  )

Issue a 1-wire READ ROM command.

The value will be returned in the order it arrives on the bus, i.e. 8 bit family code first, then 48 bit serial number, last 8 bit CRC.

On a little endian machine this will be the exact same representation as in the 1-wire data sheets, LSB first.

Note
Use ow_compute_crc(rom_code, 8) to verify the ROM code, return value should be 0x00.
Returns
64 bit ROM CODE from the bus, including CRC.

Definition at line 428 of file onewire.c.

References ow_compute_crc(), ow_read_bytes(), ow_reset(), and ow_write_bytes().

void ow_reset ( void  )

Reset the 1-wire bus.

A reset is always the first step in communicating with the bus slaves.

Definition at line 269 of file onewire.c.

Referenced by ow_match_rom(), ow_read_rom(), and ow_skip_rom().

void ow_skip_or_match_rom ( const ow_rom_code_t  id)

Shorthand function for MATCH ROM or SKIP ROM if id is zero.

Parameters
idThe ROM code of the selected device, or 0 for all devices.

Definition at line 500 of file onewire.c.

References ow_match_rom(), and ow_skip_rom().

Referenced by ds18b20_convert_temperature(), and ds18b20_read_scratchpad().

void ow_skip_rom ( void  )

Issue a 1-wire SKIP ROM command.

The SKIP ROM command is used to issue commands to all devices on the bus.

Definition at line 466 of file onewire.c.

References ow_reset(), and ow_write_bytes().

Referenced by ow_skip_or_match_rom().

void ow_write_byte ( const uint8_t  data)

Shorthand function to write a single byte to the 1-wire bus.

Parameters
datathe data byte to write.

Definition at line 348 of file onewire.c.

References ow_write_bytes().

void ow_write_bytes ( const uint8_t *  src,
const uint8_t  count 
)

Write a sequence of bytes to the 1-wire bus.

The transmission to the 1-wire bus is asynchronous, which means this function will return before all bits have gone out the wire.

Note
As src is not copied to a local buffer and the transmission is asynchronous, be careful when using stack-allocated buffers for src.
Parameters
srcthe source buffer.
countnumber of bytes to write to the bus.

Definition at line 329 of file onewire.c.

Referenced by ds18b20_convert_temperature(), ds18b20_read_scratchpad(), ow_match_rom(), ow_read_rom(), ow_skip_rom(), and ow_write_byte().