Adafruit MAX31850 OneWire Library
Public Member Functions | Static Public Member Functions | List of all members
OneWire Class Reference

Stores the state and functions for Max31850 OneWire. More...

#include <OneWire.h>

Public Member Functions

 OneWire (uint8_t pin)
 OneWire constructor. More...
 
uint8_t reset (void)
 Perform a 1-Wire reset cycle. Returns 1 if a device responds with a presence pulse. Returns 0 if there is no device or the bus is shorted or otherwise held low for more than 250uS. More...
 
void select (const uint8_t rom[8])
 Issue a 1-Wire rom select command, you do the reset first. More...
 
void skip (void)
 Issue a 1-Wire rom skip command, to address all on bus.
 
void write (uint8_t v, uint8_t power=0)
 Write a byte. If 'power' is one then the wire is held high at the end for parasitically powered devices. You are responsible for eventually depowering it by calling depower() or doing another read or write. More...
 
void write_bytes (const uint8_t *buf, uint16_t count, bool power=0)
 Writes bytes. More...
 
uint8_t read (void)
 Read a byte. More...
 
void read_bytes (uint8_t *buf, uint16_t count)
 Reads bytes. More...
 
void write_bit (uint8_t v)
 Write a bit. The bus is always left powered at the end, see note in write() about that. More...
 
uint8_t read_bit (void)
 Read a bit. More...
 
void depower (void)
 Stop forcing power onto the bus. You only need to do this if you used the 'power' flag to write() or used a write_bit() call and aren't about to do another read or write. You would rather not leave this powered if you don't have to, just in case someone shorts your bus.
 
void reset_search ()
 Clear the search state so that if will start from the beginning again.
 
void target_search (uint8_t family_code)
 Setup the search to find the device type 'family_code' on the next call to search(*newAddr) if it is present. More...
 
uint8_t search (uint8_t *newAddr)
 Look for the next device. Returns 1 if a new address has been returned. A zero might mean that the bus is shorted, there are no devices, or you have already retrieved all of them. It might be a good idea to check the CRC to make sure you didn't get garbage. The order is deterministic. You will always get the same devices in the same order. More...
 

Static Public Member Functions

static uint8_t crc8 (const uint8_t *addr, uint8_t len)
 Compute a Dallas Semiconductor 8 bit CRC, these are used in the ROM and scratchpad registers. More...
 
static bool check_crc16 (const uint8_t *input, uint16_t len, const uint8_t *inverted_crc, uint16_t crc=0)
 Compute the 1-Wire CRC16 and compare it against the received CRC. Example usage (reading a DS2408): // Put everything in a buffer so we can compute the CRC easily. uint8_t buf[13]; buf[0] = 0xF0; // Read PIO Registers buf[1] = 0x88; // LSB address buf[2] = 0x00; // MSB address WriteBytes(net, buf, 3); // Write 3 cmd bytes ReadBytes(net, buf+3, 10); // Read 6 data bytes, 2 0xFF, 2 CRC16 if (!CheckCRC16(buf, 11, &buf[11])) { // Handle error. }. More...
 
static uint16_t crc16 (const uint8_t *input, uint16_t len, uint16_t crc=0)
 Compute a Dallas Semiconductor 16 bit CRC. This is required to check the integrity of data received from many 1-Wire devices. Note that the CRC computed here is not what you'll get from the 1-Wire network, for two reasons: 1) The CRC is transmitted bitwise inverted. 2) Depending on the endian-ness of your processor, the binary representation of the two-byte return value may have a different byte order than the two bytes you get from 1-Wire. More...
 

Detailed Description

Stores the state and functions for Max31850 OneWire.

Constructor & Destructor Documentation

◆ OneWire()

OneWire::OneWire ( uint8_t  pin)

OneWire constructor.

Parameters
pinPin to use

Member Function Documentation

◆ reset()

uint8_t OneWire::reset ( void  )

Perform a 1-Wire reset cycle. Returns 1 if a device responds with a presence pulse. Returns 0 if there is no device or the bus is shorted or otherwise held low for more than 250uS.

Returns
if the reset was successful

◆ select()

void OneWire::select ( const uint8_t  rom[8])

Issue a 1-Wire rom select command, you do the reset first.

Parameters
romROM to select

◆ write()

void OneWire::write ( uint8_t  v,
uint8_t  power = 0 
)

Write a byte. If 'power' is one then the wire is held high at the end for parasitically powered devices. You are responsible for eventually depowering it by calling depower() or doing another read or write.

Parameters
vByte to write
powerIf you need power after the write then set 'power' to 1.

◆ write_bytes()

void OneWire::write_bytes ( const uint8_t *  buf,
uint16_t  count,
bool  power = 0 
)

Writes bytes.

Parameters
bufBuffer to read from
counthow many bytes to read
powerIF you need power after the write then set power to 1.

◆ read()

uint8_t OneWire::read ( void  )

Read a byte.

Returns
Returns the read byte

◆ read_bytes()

void OneWire::read_bytes ( uint8_t *  buf,
uint16_t  count 
)

Reads bytes.

Parameters
bufBuffer to read from
countHow many bytes to read

◆ write_bit()

void OneWire::write_bit ( uint8_t  v)

Write a bit. The bus is always left powered at the end, see note in write() about that.

Parameters
vBit to write

◆ read_bit()

uint8_t OneWire::read_bit ( void  )

Read a bit.

Returns
Returns the read bit

◆ target_search()

void OneWire::target_search ( uint8_t  family_code)

Setup the search to find the device type 'family_code' on the next call to search(*newAddr) if it is present.

Parameters
family_codeWhat to search for

◆ search()

uint8_t OneWire::search ( uint8_t *  newAddr)

Look for the next device. Returns 1 if a new address has been returned. A zero might mean that the bus is shorted, there are no devices, or you have already retrieved all of them. It might be a good idea to check the CRC to make sure you didn't get garbage. The order is deterministic. You will always get the same devices in the same order.

Parameters
newAddrAddress to search for
Returns
Returns true if device is found, false if it is not

◆ crc8()

uint8_t OneWire::crc8 ( const uint8_t *  addr,
uint8_t  len 
)
static

Compute a Dallas Semiconductor 8 bit CRC, these are used in the ROM and scratchpad registers.

Parameters
addrBuffer address to read from
lenHow much to read
Returns
Returns the 8-bit CRC

◆ check_crc16()

bool OneWire::check_crc16 ( const uint8_t *  input,
uint16_t  len,
const uint8_t *  inverted_crc,
uint16_t  crc = 0 
)
static

Compute the 1-Wire CRC16 and compare it against the received CRC. Example usage (reading a DS2408): // Put everything in a buffer so we can compute the CRC easily. uint8_t buf[13]; buf[0] = 0xF0; // Read PIO Registers buf[1] = 0x88; // LSB address buf[2] = 0x00; // MSB address WriteBytes(net, buf, 3); // Write 3 cmd bytes ReadBytes(net, buf+3, 10); // Read 6 data bytes, 2 0xFF, 2 CRC16 if (!CheckCRC16(buf, 11, &buf[11])) { // Handle error. }.

Parameters
inputArray of bytes to checksum.
lenHow many bytes to use.
inverted_crcThe two CRC16 bytes in the received data. This should just point into the received data, not at a 16-bit integer.
crcThe crc starting value (optional)
Returns
True, if the CRC matches.

◆ crc16()

uint16_t OneWire::crc16 ( const uint8_t *  input,
uint16_t  len,
uint16_t  crc = 0 
)
static

Compute a Dallas Semiconductor 16 bit CRC. This is required to check the integrity of data received from many 1-Wire devices. Note that the CRC computed here is not what you'll get from the 1-Wire network, for two reasons: 1) The CRC is transmitted bitwise inverted. 2) Depending on the endian-ness of your processor, the binary representation of the two-byte return value may have a different byte order than the two bytes you get from 1-Wire.

Parameters
inputArray of bytes to checksum.
lenHow many bytes to use.
crcThe crc starting value (optional)
Returns
Returns the CRC16, as defined by Dallas Semiconductor.

The documentation for this class was generated from the following files: