1-Wire and ENS210 driver stack
Classes | Enumerations | Functions | Variables
DS28E18.h File Reference

General library for the DS28E18. More...

#include <stdint.h>
#include <stdbool.h>
#include "one_wire.h"
Include dependency graph for DS28E18.h:

Go to the source code of this file.

Classes

struct  DS28E18_sequence_T
 

Enumerations

enum  DS28E18_device_function_commands_T {
  COMMAND_START = 0x66, WRITE_SEQUENCER = 0x11, READ_SEQUENCER = 0x22, RUN_SEQUENCER = 0x33,
  WRITE_CONFIGURATION = 0x55, READ_CONFIGURATION = 0x6A, WRITE_GPIO_CONFIGURATION = 0x83, READ_GPIO_CONFIGURATION = 0x7C,
  DEVICE_STATUS = 0x7A
}
 
enum  DS28E18_one_wire_rom_commands_T {
  READ_ROM = 0x33, MATCH_ROM = 0x55, SEARCH_ROM = 0xF0, SKIP_ROM = 0xCC,
  RESUME = 0xA5, OVERDRIVE_SKIP = 0x3C, OVERDRIVE_MATCH = 0x69
}
 
enum  DS28E18_sequencer_commands_T {
  I2C_START = 0x02, I2C_STOP = 0x03, I2C_WRITE_DATA = 0xE3, I2C_READ_DATA = 0xD4,
  I2C_READ_DATA_W_NACK_END = 0xD3, SPI_WRITE_READ_BYTE = 0xC0, SPI_WRITE_READ_BIT = 0xB0, SPI_SS_HIGH = 0x01,
  SPI_SS_LOW = 0x80, UTILITY_DELAY = 0xDD, UTILITY_SENS_VDD_ON = 0xCC, UTILITY_SENS_VDD_OFF = 0xBB,
  UTILITY_GPIO_BUF_WRITE = 0xD1, UTILITY_GPIO_BUF_READ = 0x1D, UTILITY_GPIO_CNTL_WRITE = 0xE2, UTILITY_GPIO_CNTL_READ = 0x2E
}
 
enum  DS28E18_result_byte_T {
  POR_OCCURRED = 0x44, EXECUTION_ERROR = 0x55, INVALID_PARAMETER = 0x77, NACK_OCCURED = 0x88,
  SUCCESS = 0xAA
}
 
enum  DS28E18_protocol_speed_T { KHZ_100, KHZ_400, KHZ_1000, KHZ_2300 }
 
enum  DS28E18_ignore_nack_T { DONT_IGNORE, IGNORE }
 
enum  DS28E18_protocol_T { I2C, SPI }
 
enum  DS28E18_spi_mode_T { MODE_0 = 0x00, MODE_3 = 0x03 }
 
enum  DS28E18_target_configuration_register_T { CONTROL = 0x0B, BUFFER = 0x0C }
 
enum  DS28E18_utility_delay_T {
  DELAY_1msec = 0, DELAY_2msec = 1, DELAY_4msec = 2, DELAY_8msec = 3,
  DELAY_16msec = 4, DELAY_32msec = 5, DELAY_64msec = 6, DELAY_128msec = 7,
  DELAY_256msec = 8, DELAY_512msec = 9, DELAY_1024msec = 10, DELAY_2048msec = 11,
  DELAY_4096msec = 12, DELAY_8192msec = 13, DELAY_16384msec = 14, DELAY_32768msec = 15
}
 

Functions

int DS28E18_Init (void)
 
int DS28E18_SetOnewireSpeed (one_wire_speeds spd)
 
void DS28E18_SetRomCommand (DS28E18_one_wire_rom_commands_T rom_cmd)
 
DS28E18_one_wire_rom_commands_T DS28E18_GetRomCommand (void)
 Return the value of 'current_ROM_command'.
 
bool DS28E18_WriteSequencer (unsigned short nineBitStartingAddress, const uint8_t *txData, int txDataSize)
 
bool DS28E18_ReadSequencer (unsigned short nineBitStartingAddress, uint8_t *rxData, unsigned short readLength)
 
bool DS28E18_RunSequencer (unsigned short nineBitStartingAddress, unsigned short runLength)
 
bool DS28E18_WriteConfiguration (DS28E18_protocol_speed_T SPD, DS28E18_ignore_nack_T INACK, DS28E18_protocol_T PROT, DS28E18_spi_mode_T SPI_MODE)
 
bool DS28E18_ReadConfiguration (uint8_t *rxData)
 
bool DS28E18_WriteGpioConfiguration (DS28E18_target_configuration_register_T CFG_REG_TARGET, uint8_t GPIO_HI, uint8_t GPIO_LO)
 
bool DS28E18_ReadGpioConfiguration (uint8_t CFG_REG_TARGET, uint8_t *rxData)
 
bool DS28E18_DeviceStatus (uint8_t *rxData)
 
void DS28E18_BuildPacket_ClearSequencerPacket (void)
 Reset local command sequencer packet under construction.
 
uint8_t * DS28E18_BuildPacket_GetSequencerPacket (void)
 Get address of locally constructed command sequencer packet's data.
 
int DS28E18_BuildPacket_GetSequencerPacketSize (void)
 Get length of locally constructed command sequencer packet.
 
void DS28E18_BuildPacket_I2C_Start (void)
 
void DS28E18_BuildPacket_I2C_Stop (void)
 
void DS28E18_BuildPacket_I2C_WriteData (const uint8_t *i2cData, uint8_t i2cDataSize)
 
unsigned short DS28E18_BuildPacket_I2C_ReadData (int readBytes)
 
unsigned short DS28E18_BuildPacket_I2C_ReadDataWithNackEnd (int readBytes)
 
unsigned short DS28E18_BuildPacket_SPI_WriteReadByte (const uint8_t *spiWriteData, uint8_t spiWriteDataSize, int readBytes, bool fullDuplex)
 
unsigned short DS28E18_BuildPacket_SPI_WriteReadBit (const uint8_t *spiWriteData, uint8_t spiWriteDataSize, int writeBits, int readBits)
 
void DS28E18_BuildPacket_SPI_SlaveSelectHigh (void)
 
void DS28E18_BuildPacket_SPI_SlaveSelectLow (void)
 
void DS28E18_BuildPacket_Utility_Delay (DS28E18_utility_delay_T delayTimeInMsExponent)
 
void DS28E18_BuildPacket_Utility_SensVddOn (void)
 
void DS28E18_BuildPacket_Utility_SensVddOff (void)
 
void DS28E18_BuildPacket_Utility_GpioBufferWrite (uint8_t GPIO_BUF)
 
unsigned short DS28E18_BuildPacket_Utility_GpioBufferRead (void)
 
void DS28E18_BuildPacket_Utility_GpioControlWrite (uint8_t GPIO_CRTL_HI, uint8_t GPIO_CRTL_LO)
 
unsigned short DS28E18_BuildPacket_Utility_GpioControlRead (void)
 
void DS28E18_BuildPacket_Append (const uint8_t *sequencerCmds, size_t length)
 Append commands to locally constructed command sequencer packet.
 
bool DS28E18_BuildPacket_WriteAndRun (void)
 

Variables

OneWire_ROM_ID_T current_DS28E18_ROM_ID
 DS28E18 device addressed for current operations (may be one of many on 1-Wire bus)
 

Detailed Description

General library for the DS28E18.

Enumeration Type Documentation

◆ DS28E18_one_wire_rom_commands_T

Enumerator
READ_ROM 

can only be used if there is a single slave on the bus

MATCH_ROM 

address a specific slave by ROM ID

SEARCH_ROM 

enumeration of all slaves on bus

SKIP_ROM 

don't use ROM ID (applicable only when there is only 1 slave on the bus)

OVERDRIVE_MATCH 

selected (matched ROM ID) slave goes into overdrive

◆ DS28E18_utility_delay_T

DS28E18 delay command argument is an exponent: Delay is 2^arg in msec. The actual delay time is from 1ms to 32s respectively Code relies on enum defined as the exponent as below.

Function Documentation

◆ DS28E18_BuildPacket_I2C_ReadData()

unsigned short DS28E18_BuildPacket_I2C_ReadData ( int  readBytes)

Sequencer Command: Read Data (D4h).

Append an I2C Read Data command to the locally constructed command sequencer packet.

Parameters
readBytesNumber of bytes to read from the I2C bus
Returns
readArrayFFhStartingAddress - Address where I2C slave response will reside

◆ DS28E18_BuildPacket_I2C_ReadDataWithNackEnd()

unsigned short DS28E18_BuildPacket_I2C_ReadDataWithNackEnd ( int  readBytes)

Sequencer Command: Read Data w/NACK end (D3h).

Append an I2C Read Data w/NACK end command to the locally constructed command sequencer packet.

Parameters
readBytesNumber of bytes to read from the I2C bus
Returns
readArrayFFhStartingAddress - Address where I2C slave response will reside

◆ DS28E18_BuildPacket_I2C_Start()

void DS28E18_BuildPacket_I2C_Start ( void  )

Sequencer Command: Start (02h).

Append an I2C Start command to the locally constructed command sequencer packet.

◆ DS28E18_BuildPacket_I2C_Stop()

void DS28E18_BuildPacket_I2C_Stop ( void  )

Sequencer Command: Stop (03h).

Append an I2C Stop command to the locally constructed command sequencer packet.

◆ DS28E18_BuildPacket_I2C_WriteData()

void DS28E18_BuildPacket_I2C_WriteData ( const uint8_t *  i2cData,
uint8_t  i2cDataSize 
)

Sequencer Command: Write Data (E3h).

Append an I2C Write Data command to the locally constructed command sequencer packet.

Parameters
i2cDataArray with data to be transmitted over the I2C bus
i2cDataSizeNumber of elements found in i2cData array

◆ DS28E18_BuildPacket_SPI_SlaveSelectHigh()

void DS28E18_BuildPacket_SPI_SlaveSelectHigh ( void  )

Sequencer Command: SPI SS_High (01h).

Append an SPI SS_High command to the locally constructed command sequencer packet.

◆ DS28E18_BuildPacket_SPI_SlaveSelectLow()

void DS28E18_BuildPacket_SPI_SlaveSelectLow ( void  )

Sequencer Command: SPI SS_Low (80h).

Append an SPI SS_Low command to the locally constructed command sequencer packet.

◆ DS28E18_BuildPacket_SPI_WriteReadBit()

unsigned short DS28E18_BuildPacket_SPI_WriteReadBit ( const uint8_t *  spiWriteData,
uint8_t  spiWriteDataSize,
int  writeBits,
int  readBits 
)

Sequencer Command: SPI Write/Read Bit (B0h).

Append an SPI Write/Read Bit command to the locally constructed command sequencer packet.

Parameters
spiWriteDataArray with data to be transmitted over the SPI bus. Data not important if only reading.
spiWriteDataSizeNumber of elements found in spiWriteData array. Set to 0 if only reading.
writeBitsNumber of bits to write to SPI bus. Set to 0 if only reading.
readBitsNumber of bits to read from SPI bus. Set to 0 if only writting.
Returns
readArrayFFhStartingAddress - If reading, address where SPI slave response will reside.

◆ DS28E18_BuildPacket_SPI_WriteReadByte()

unsigned short DS28E18_BuildPacket_SPI_WriteReadByte ( const uint8_t *  spiWriteData,
uint8_t  spiWriteDataSize,
int  readBytes,
bool  fullDuplex 
)

Sequencer Command: SPI Write/Read Byte (C0h).

Append an SPI Write/Read Byte command to the locally constructed command sequencer packet.

Parameters
spiWriteDataArray with data to be transmitted over the SPI bus. Data not important if only reading.
spiWriteDataSizeNumber of elements found in spiWriteData array. Set to 0 if only reading.
readBytesNumber of bytes to read from SPI bus. Set to 0 if only writting.
fullDuplexSet 'true' when interfacing with a full duplex SPI slave. Otherwise, set 'false'
Returns
readArrayFFhStartingAddress - If reading, address where SPI slave response will reside.

◆ DS28E18_BuildPacket_Utility_Delay()

void DS28E18_BuildPacket_Utility_Delay ( DS28E18_utility_delay_T  delayTimeInMsExponent)

Sequencer Command: Delay (DDh).

Append a Delay command to the locally constructed command sequencer packet.

◆ DS28E18_BuildPacket_Utility_GpioBufferRead()

unsigned short DS28E18_BuildPacket_Utility_GpioBufferRead ( void  )

Sequencer Command: GPIO_BUF Read (1Dh).

Append a GPIO_BUF Read command to the locally constructed command sequencer packet.

Returns
readArrayFFhStartingAddress - Starting address where configuration data will reside.

◆ DS28E18_BuildPacket_Utility_GpioBufferWrite()

void DS28E18_BuildPacket_Utility_GpioBufferWrite ( uint8_t  GPIO_BUF)

Sequencer Command: GPIO_BUF Write (D1h).

Append a GPIO_BUF Write command to the locally constructed command sequencer packet.

Parameters
GPIO_BUFBuffer register high byte.

◆ DS28E18_BuildPacket_Utility_GpioControlRead()

unsigned short DS28E18_BuildPacket_Utility_GpioControlRead ( void  )

Sequencer Command: GPIO_CNTL Read (2Eh).

Append a GPIO_CNTL Read command to the locally constructed command sequencer packet.

Returns
readArrayFFhStartingAddress - Starting address where configuration data will reside.

◆ DS28E18_BuildPacket_Utility_GpioControlWrite()

void DS28E18_BuildPacket_Utility_GpioControlWrite ( uint8_t  GPIO_CRTL_HI,
uint8_t  GPIO_CRTL_LO 
)

Sequencer Command: GPIO_CNTL Write (E2h).

Append a GPIO_CNTL Write command to the locally constructed command sequencer packet.

Parameters
GPIO_CRTL_HIControl register high byte.
GPIO_CRTL_LOControl register low byte.

◆ DS28E18_BuildPacket_Utility_SensVddOff()

void DS28E18_BuildPacket_Utility_SensVddOff ( void  )

Sequencer Command: SENS_VDD Off (BBh).

Append a 'SENS_VDD Off' command to the locally constructed command sequencer packet.

◆ DS28E18_BuildPacket_Utility_SensVddOn()

void DS28E18_BuildPacket_Utility_SensVddOn ( void  )

Sequencer Command: SENS_VDD On (CCh).

Append a 'SENS_VDD On' command to the locally constructed command sequencer packet.

◆ DS28E18_BuildPacket_WriteAndRun()

bool DS28E18_BuildPacket_WriteAndRun ( void  )

Write locally constructed command sequencer packet into DS28E18's sequence memory over 1wire, run it, and wait long enough for completion. Does NOT fetch any response; use DS28E18_ReadSequencer for that.

◆ DS28E18_DeviceStatus()

bool DS28E18_DeviceStatus ( uint8_t *  rxData)

Device Function Command: Device Status (7Ah)

Parameters
rxData[out]Array of 4 bytes to receive DS28E18's status information
Returns
true - command successful
false - command failed

◆ DS28E18_Init()

int DS28E18_Init ( void  )

Initialize all DS28E18 on the 1-Wire bus.

Returns
number of DS28E18 found on the bus.

◆ DS28E18_ReadConfiguration()

bool DS28E18_ReadConfiguration ( uint8_t *  rxData)

Device Function Command: Read Configuration (6Ah)

Parameters
rxData[out]Array of 2 bytes to be updated with devices' configuration information
Returns
true - command successful
false - command failed

◆ DS28E18_ReadGpioConfiguration()

bool DS28E18_ReadGpioConfiguration ( uint8_t  CFG_REG_TARGET,
uint8_t *  rxData 
)

Device Function Command: Read GPIO Configuration (7Ch)

Parameters
CFG_REG_TARGETDesired GPIO Configuration Register from macros to read from
rxData[out]Array of 2 bytes to be updated with device current GPIO configuration for GPIO_HI and GPIO_LO
Returns
true - command successful
false - command failed

◆ DS28E18_ReadSequencer()

bool DS28E18_ReadSequencer ( unsigned short  nineBitStartingAddress,
uint8_t *  rxData,
unsigned short  readLength 
)

Device Function Command: Read Sequencer (22h)

Parameters
nineBitStartingAddressTarget read address
readLengthNumber of data bytes to be read from the sequencer memory starting from the target read address
[out]rxDataArray of data returned from specified memory address
Returns
true - command successful
false - command failed

◆ DS28E18_RunSequencer()

bool DS28E18_RunSequencer ( unsigned short  nineBitStartingAddress,
unsigned short  runLength 
)

Device Function Command: Run Sequencer (33h) - Command DS28E18 over 1wire to run a command sequence already placed in DS28E18 sequence memory

Parameters
nineBitStartingAddressTarget run address
runLengthNumber of data bytes to run from the sequencer memory starting from the target run address
Returns
true - command successful
false - command failed

◆ DS28E18_SetOnewireSpeed()

int DS28E18_SetOnewireSpeed ( one_wire_speeds  spd)

Set desired 1-Wire speed between Standard and Overdrive for both, 1-Wire master and slave.

Returns
0 - At least one device is detected after a 1-Wire reset is performed on new speed. 1 - Failure.

◆ DS28E18_SetRomCommand()

void DS28E18_SetRomCommand ( DS28E18_one_wire_rom_commands_T  rom_cmd)

Set 1-Wire 'current_ROM_command' (normally MATCH_ROM, SKIP_ROM during device search). Does not send anything to lower-level code; just sets the operating mode for this DS28E18 layer.

◆ DS28E18_WriteConfiguration()

bool DS28E18_WriteConfiguration ( DS28E18_protocol_speed_T  SPD,
DS28E18_ignore_nack_T  INACK,
DS28E18_protocol_T  PROT,
DS28E18_spi_mode_T  SPI_MODE 
)

Device Function Command: Write Configuration (55h)

Parameters
SPDDesired protocol speed from macros
INACKDesired INACK configuration from macros
PROTDesired protocol from macros
SPI_MODEDesired SPI Mode from macros
Returns
true - command successful
false - command failed

◆ DS28E18_WriteGpioConfiguration()

bool DS28E18_WriteGpioConfiguration ( DS28E18_target_configuration_register_T  CFG_REG_TARGET,
uint8_t  GPIO_HI,
uint8_t  GPIO_LO 
)

Device Function Command: Write GPIO Configuration (83h)

Parameters
CFG_REG_TARGETDesired GPIO Configuration Register to write to
GPIO_HIControl/Buffer register high byte
GPIO_LOControl/Buffer register low byte
Returns
true - command successful
false - command failed
Note
Use GPIO Configuration functions to help build GPIO_HI/GPIO_LO parameter.

◆ DS28E18_WriteSequencer()

bool DS28E18_WriteSequencer ( unsigned short  nineBitStartingAddress,
const uint8_t *  txData,
int  txDataSize 
)

Device Function Command: Write Sequencer (11h) - Write command sequence into DS28E28 sequencer memory over 1Wire

Parameters
nineBitStartingAddressTarget write address
txDataArray of data to be written into the sequencer memory starting from the target write address
txDataSizeNumber of elements found in txData array
Returns
true - command successful
false - command failed
Note
Use Sequencer Commands functions to help build txData array.