Difference between revisions of "Component: One Wire (Comms: Interface)"

From Flowcode Help
Jump to navigationJump to search
Line 53: Line 53:
 
*[[Component:_Temperature_(DS18B20)_(Environmental)|DS18B20 Temperature Sensor]]
 
*[[Component:_Temperature_(DS18B20)_(Environmental)|DS18B20 Temperature Sensor]]
 
*[[Component:_Temperature_(DS18S20)_(Environmental)|DS18S20 Temperature Sensor]]
 
*[[Component:_Temperature_(DS18S20)_(Environmental)|DS18S20 Temperature Sensor]]
 +
 +
  
 
==Downloadable macro reference==
 
==Downloadable macro reference==

Revision as of 14:49, 13 August 2021


Author Matrix Ltd
Version 1.3 (Release)
Category Comms: Interface


Image One Wire component

Low level routines for controlling or interacting with a standard one wire interface.

Examples

Device Scanning

To get started with one wire devices it is often useful to collect the unique device serial number for each and every one wire device you are going to connect to your bus.

For example if you have a bus with two temperature sensors connected it is useful to know which sensor is which. Sensor A is monitoring temperature A and sensor B is monitoring temperature B. The only way to tell which is which is to use the serial number.

Here is a program that scans for devices on a one wire bus and outputs the device count and serial numbers using a LCD.

FC6 Icon.png One Wire Device Scan LCD


Here is the same program but this time the device count and serial numbers are output using a UART such as on an Arduino or ESP32.

FC6 Icon.png One Wire Device Scan Serial


OneWireDeviceScan.jpg


To use the examples simply connect a single device to the one wire bus and make a note of the reported serial number.

This serial number can then be entered into the specific one wire component and used to ensure you are communicating with the device you think you are.

A pull up resistor of between 1K and 10K is required between the data I/O pin and VCC.


Further Examples

The One Wire component is a key building block required by a number of other components. Some of which are included below.


Downloadable macro reference

ReceiveByte

Receives a byte from the one wire bus a bit at a time

Parameters

This macro has no parameters


Return value

BYTE


WriteScratchpad

Writes to the scratchpad for the selected device.

Must be called after a MatchROM macro call.

Parameters

BYTE Data
BYTE Count


Return value

This call does not return a value


TransmitByte

Transmit a byte to the one wire bus a bit at a time

Parameters

BYTE Command


Return value

This call does not return a value


SkipROM

Performs a bus reset and the sends the SkipROM command byte

Parameters

This macro has no parameters


Return value

This call does not return a value


BusReset

Issue a 'ping' on the bus. If there is at least one sensor on the bus then it will generate a presence pulse.


Returns 0 if a presense pulse was detected

Returns 1 no device was detected

Parameters

This macro has no parameters


Return value

BOOL : Returns true if the operation is a success, else false


MatchROM

Performs a reset followed by the MatchROM code and then the 8-bit ROM code.

Parameters

BYTE FamilyCode
BYTE SerialNumber


Return value

This call does not return a value


ReadScratchpad

Reads the 9-Byte scratchpad for the selected device.

Must be called after a MatchROM macro call.

Parameters

This macro has no parameters


Return value

This call does not return a value


ScanBus

Scans the one wire bus to detect all connected devices.

Returns the number of one wire devices found.

Parameters

This macro has no parameters


Return value

BYTE


GetDeviceCount

Returns the number of devices found by the last ScanBus operation.

Parameters

This macro has no parameters


Return value

BYTE


GetScratchpadByte

Returns a byte from the last read scratchpad at position index.

The index byte can go from 0 - 8 to reference the 9 individual scratchpad bytes.

Parameters

BYTE Index
Select which pad byte to use 0-8


Return value

BYTE


GetIDByte

Returns byte ectet of the 64-Bit lasered ROM code, 255 on error

Parameters

BYTE Device
Device ID - Range: 0 - NumDevices - 1
BYTE ByteIndex
Index of the data byte. 0=FamilyCode, 1-6=Serial, 7=CRC


Return value

BYTE


Initialise

Sets up the 1-Wire output pin ready for communications.

Parameters

This macro has no parameters


Return value

This call does not return a value


Simulation macro reference

This component does not contain any simulation macros


Property reference

One Wire Pin

This property is of type Single digital pin and can be referenced with the variable name oo_pin.

I/O pin used to host one wire bus.

Timing

This property is of type Fixed list of ints and can be referenced with the variable name Timing.

Sets the component timing model.

Standard is the usual 1-wire timing,

Overdrive is a high speed 1-wire timing.

Max Devices

This property is of type Unsigned integer and can be referenced with the variable name BufferSize.

Controls the maximum number of devices that can be detected during a ScanBus.

For each additional device we require 8 bytes to store the ROM ID.

Default: 8 = 64 Bytes of RAM