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

From Flowcode Help
Jump to navigationJump to search
Line 54: Line 54:
 
==Downloadable macro reference==
 
==Downloadable macro reference==
  
===<span style="font-weight: normal;"><u><tt>DS1820_StartConversion</tt></u></span>===
+
===<span style="font-weight: normal;"><u><tt>ReceiveByte</tt></u></span>===
DS1820 device specific function
+
Receives a byte from the one wire bus a bit at a time
 
 
Commands all sensors to start a temperature conversion
 
  
 
'''Parameters'''
 
'''Parameters'''
Line 69: Line 67:
  
  
===<span style="font-weight: normal;"><u><tt>ReceiveByte</tt></u></span>===
+
===<span style="font-weight: normal;"><u><tt>WriteScratchpad</tt></u></span>===
Receives a byte from the one wire bus a bit at a time
+
Writes to the scratchpad for the selected device.
 +
 
 +
Must be called after a MatchROM macro call.
  
 
'''Parameters'''
 
'''Parameters'''
  
:''This macro has no parameters''
+
:[[Variable Types|BYTE]] ''Data''
 +
 
 +
:[[Variable Types|BYTE]] ''Count''
  
  
 
'''Return value'''
 
'''Return value'''
  
:[[Variable Types|BYTE]]
+
:''This call does not return a value''
  
  
Line 95: Line 97:
  
  
===<span style="font-weight: normal;"><u><tt>GetPadByte</tt></u></span>===
+
===<span style="font-weight: normal;"><u><tt>SkipROM</tt></u></span>===
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.
+
Performs a bus reset and the sends the SkipROM command byte
  
 
'''Parameters'''
 
'''Parameters'''
  
:[[Variable Types|BYTE]] ''Index''
+
:''This macro has no parameters''
::Select which pad byte to use 0-8
 
  
  
 
'''Return value'''
 
'''Return value'''
  
:[[Variable Types|BYTE]]
+
:''This call does not return a value''
  
  
Line 125: Line 126:
 
'''Return value'''
 
'''Return value'''
  
:[[Variable Types|BYTE]]
+
:[[Variable Types|BOOL]] : Returns true if the operation is a success, else false
 +
 
 +
 
 +
===<span style="font-weight: normal;"><u><tt>MatchROM</tt></u></span>===
 +
Performs a reset followed by the MatchROM code and then the 8-bit ROM code.
 +
 
 +
'''Parameters'''
 +
 
 +
:[[Variable Types|BYTE]] ''FamilyCode''
 +
 
 +
:[[Variable Types|BYTE]] ''SerialNumber''
 +
 
 +
 
 +
'''Return value'''
 +
 
 +
:''This call does not return a value''
 +
 
  
 +
===<span style="font-weight: normal;"><u><tt>ReadScratchpad</tt></u></span>===
 +
Reads the 9-Byte scratchpad for the selected device.
  
===<span style="font-weight: normal;"><u><tt>ScanBus</tt></u></span>===
+
Must be called after a MatchROM macro call.
Scans the one wire bus to detect all devices
 
  
 
'''Parameters'''
 
'''Parameters'''
Line 138: Line 156:
 
'''Return value'''
 
'''Return value'''
  
:[[Variable Types|BYTE]]
+
:''This call does not return a value''
 +
 
  
 +
===<span style="font-weight: normal;"><u><tt>ScanBus</tt></u></span>===
 +
Scans the one wire bus to detect all connected devices.
  
===<span style="font-weight: normal;"><u><tt>GetDeviceCount</tt></u></span>===
+
Returns the number of one wire devices found.
Returns the number of detected devices
 
  
 
'''Parameters'''
 
'''Parameters'''
Line 154: Line 174:
  
  
===<span style="font-weight: normal;"><u><tt>GetIDByte</tt></u></span>===
+
===<span style="font-weight: normal;"><u><tt>GetDeviceCount</tt></u></span>===
Returns byte ectet of the 64-Bit lasered ROM code, 255 on error
+
Returns the number of devices found by the last ScanBus operation.
  
 
'''Parameters'''
 
'''Parameters'''
  
:[[Variable Types|BYTE]] ''device''
+
:''This macro has no parameters''
 
 
:[[Variable Types|BYTE]] ''octet''
 
  
  
Line 169: Line 187:
  
  
===<span style="font-weight: normal;"><u><tt>DS1820_ReadScratchpad</tt></u></span>===
+
===<span style="font-weight: normal;"><u><tt>GetScratchpadByte</tt></u></span>===
Reads the scratchpad of the currently selected device
+
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'''
 
'''Parameters'''
  
:''This macro has no parameters''
+
:[[Variable Types|BYTE]] ''Index''
 +
::Select which pad byte to use 0-8
  
  
Line 182: Line 203:
  
  
===<span style="font-weight: normal;"><u><tt>ReadDevice</tt></u></span>===
+
===<span style="font-weight: normal;"><u><tt>GetIDByte</tt></u></span>===
Reads the temperature of the device at location count in the id array
+
Returns byte ectet of the 64-Bit lasered ROM code, 255 on error
  
 
'''Parameters'''
 
'''Parameters'''
  
:[[Variable Types|BYTE]] ''count''
+
:[[Variable Types|BYTE]] ''Device''
 +
::Device ID - Range: 0 - NumDevices - 1
 +
 
 +
:[[Variable Types|BYTE]] ''ByteIndex''
 +
::Index of the data byte. 0=FamilyCode, 1-6=Serial, 7=CRC
  
  
Line 195: Line 220:
  
  
===<span style="font-weight: normal;"><u><tt>DS1820_GetTemp</tt></u></span>===
+
===<span style="font-weight: normal;"><u><tt>Initialise</tt></u></span>===
Returns the two byte value of the temperature sensor
+
Sets up the 1-Wire output pin ready for communications.
  
 
'''Parameters'''
 
'''Parameters'''
Line 205: Line 230:
 
'''Return value'''
 
'''Return value'''
  
:[[Variable Types|UINT]]
+
:''This call does not return a value''
  
  
Line 221: Line 246:
 
I/O pin used to host one wire bus.
 
I/O pin used to host one wire bus.
  
<span style="font-weight: normal;"><u>CRC Enabled</u></span>
+
<span style="font-weight: normal;"><u>Timing</u></span>
 +
 
 +
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''Timing''.
  
This property is of type ''True or false'' and can be referenced with the variable name ''crc_en''.
+
Sets the component timing model.
  
Sets the CRC bit based error detection on or off. (cyclic redundancy check)
+
Standard is the usual 1-wire timing,
  
<span style="font-weight: normal;"><u>Label</u></span>
+
Overdrive is a high speed 1-wire timing.
  
This property is of type ''Line of text'' and can be referenced with the variable name ''label''.
+
<span style="font-weight: normal;"><u>Max Devices</u></span>
  
Label to draw on the GUI object for identification
+
This property is of type ''Unsigned integer'' and can be referenced with the variable name ''BufferSize''.
  
<span style="font-weight: normal;"><u>Injector</u></span>
+
Controls the maximum number of devices that can be detected during a ScanBus.
  
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''Injector''.
+
For each additional device we require 8 bytes to store the ROM ID.
  
Lists all the current injector components available on the user's panel
+
Default: 8 = 64 Bytes of RAM

Revision as of 13:20, 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.

[DS18B20]

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