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

From Flowcode Help
Jump to navigationJump to search
 
(22 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
+
{| style="width:50%"
 
 
{| width="50%"
 
 
|-
 
|-
| width="20%" style="color: gray;" | Author
+
| width="20%" style="color:gray;" | Author
 
| Matrix Ltd
 
| Matrix Ltd
 
|-
 
|-
| width="20%" style="color: gray;" | Version
+
| width="20%" style="color:gray;" | Version
| 1.3 (Release)
+
| 1.4
 
|-
 
|-
| width="20%" style="color: gray;" | Category
+
| width="20%" style="color:gray;" | Category
 
| Comms: Interface
 
| Comms: Interface
 
|}
 
|}
  
  
 
+
==One Wire component==
==[[File:Component Icon 64b26b13_68cf_4a92_8616_e882b7c71023.png|Image]] One Wire component==
 
 
Low level routines for controlling or interacting with a standard one wire interface.
 
Low level routines for controlling or interacting with a standard one wire interface.
  
==Examples==
+
==Component Source Code==
  
===Device Scanning===
+
Please click here to download the component source project: [https://www.flowcode.co.uk/wiki/componentsource/FC_Comp_Source_One_Wire.fcfx FC_Comp_Source_One_Wire.fcfx]
  
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.
+
Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_One_Wire.fcfx FC_Comp_Source_One_Wire.fcfx]
  
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.
+
==Detailed description==
  
Here is a program that scans for devices on a one wire bus and outputs the device count and serial numbers using a LCD.
 
  
{{fcfile|OneWire_Device_ID_LCD.fcfx|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.
 
  
{{fcfile|OneWire_Device_ID_Serial.fcfx|One Wire Device Scan Serial}}
 
  
  
[[file: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==
 
  
===<span style="font-weight: normal;"><u><tt>ReceiveByte</tt></u></span>===
 
Receives a byte from the one wire bus a bit at a time
 
  
'''Parameters'''
 
  
:''This macro has no parameters''
 
  
  
'''Return value'''
 
  
:[[Variable Types|BYTE]]
 
  
 +
''No detailed description exists yet for this component''
  
===<span style="font-weight: normal;"><u><tt>WriteScratchpad</tt></u></span>===
+
==Examples==
Writes to the scratchpad for the selected device.
 
  
Must be called after a MatchROM macro call.
 
  
'''Parameters'''
 
  
:[[Variable Types|BYTE]] ''Data''
 
  
:[[Variable Types|BYTE]] ''Count''
 
  
  
'''Return value'''
 
  
:''This call does not return a value''
 
  
  
===<span style="font-weight: normal;"><u><tt>TransmitByte</tt></u></span>===
 
Transmit a byte to the one wire bus a bit at a time
 
  
'''Parameters'''
 
  
:[[Variable Types|BYTE]] ''Command''
 
  
  
'''Return value'''
 
  
:''This call does not return a value''
 
  
  
===<span style="font-weight: normal;"><u><tt>SkipROM</tt></u></span>===
 
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''
 
  
  
===<span style="font-weight: normal;"><u><tt>BusReset</tt></u></span>===
 
Issue a 'ping' on the bus. If there is at least one sensor on the bus then it will generate a presence pulse.
 
  
  
 +
===Device Scanning===
  
Returns 0 if a presense pulse was detected
+
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.
  
Returns 1 no device was detected
+
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.
  
'''Parameters'''
+
Here is a program that scans for devices on a one wire bus and outputs the device count and serial numbers using a LCD.
  
:''This macro has no parameters''
+
{{fcfile|OneWire_Device_ID_LCD.fcfx|One Wire Device Scan LCD}}
  
  
'''Return value'''
+
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.
  
:[[Variable Types|BOOL]] : Returns true if the operation is a success, else false
+
{{fcfile|OneWire_Device_ID_Serial.fcfx|One Wire Device Scan Serial}}
  
  
===<span style="font-weight: normal;"><u><tt>MatchROM</tt></u></span>===
+
[[file:OneWireDeviceScan.jpg]]
Performs a reset followed by the MatchROM code and then the 8-bit ROM code.
 
  
'''Parameters'''
 
  
:[[Variable Types|BYTE]] ''FamilyCode''
+
To use the examples simply connect a single device to the one wire bus and make a note of the reported serial number.
  
:[[Variable Types|BYTE]] ''SerialNumber''
+
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.
  
'''Return value'''
 
  
:''This call does not return a value''
+
===Further Examples===
  
 +
The One Wire component is a key building block required by a number of other components. Some of which are included below.
  
===<span style="font-weight: normal;"><u><tt>ReadScratchpad</tt></u></span>===
+
*[[Component:_Temperature_(DS1822)_(Environmental)|DS1822 Temperature Sensor]]
Reads the 9-Byte scratchpad for the selected device.
+
*[[Component:_Temperature_(DS18B20)_(Environmental)|DS18B20 Temperature Sensor]]
 +
*[[Component:_Temperature_(DS18S20)_(Environmental)|DS18S20 Temperature Sensor]]
 +
*[[Component:_EEPROM_(DS28E07)_(Storage)|DS28E07 128 Byte EEPROM]]
 +
*[[Component:_IButton_(DS1990)_(Storage)|DS1990 iButton Unique 48-bit ID]]
  
Must be called after a MatchROM macro call.
 
  
'''Parameters'''
+
Example One Wire comms component being referenced by several specific One Wire device library components.
  
:''This macro has no parameters''
+
[[File:OneWire.jpg]]
  
  
'''Return value'''
 
  
:''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.
 
  
Returns the number of one wire devices found.
 
  
'''Parameters'''
 
  
:''This macro has no parameters''
 
  
  
'''Return value'''
 
  
:[[Variable Types|BYTE]]
+
==Macro reference==
  
 +
===BusReset===
 +
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''BusReset'''
 +
|-
 +
| colspan="2" | 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&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-bool-icon.png]] - BOOL
 +
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
  
===<span style="font-weight: normal;"><u><tt>GetDeviceCount</tt></u></span>===
 
Returns the number of devices found by the last ScanBus operation.
 
  
'''Parameters'''
+
===GetDeviceCount===
 +
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetDeviceCount'''
 +
|-
 +
| colspan="2" | Returns the number of devices found by the last ScanBus operation.&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
  
:''This macro has no parameters''
 
  
 +
===GetIDByte===
 +
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetIDByte'''
 +
|-
 +
| colspan="2" | Returns byte ectet of the 64-Bit lasered ROM code, 255 on error&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | Device
 +
|-
 +
| colspan="2" | Device ID - Range: 0 - NumDevices - 1&nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | ByteIndex
 +
|-
 +
| colspan="2" | Index of the data byte. 0=FamilyCode, 1-6=Serial, 7=CRC&nbsp;
 +
|-
 +
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
  
'''Return value'''
 
  
:[[Variable Types|BYTE]]
+
===Initialise===
 +
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Initialise'''
 +
|-
 +
| colspan="2" | Sets up the 1-Wire output pin ready for communications.&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
 +
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
  
  
===<span style="font-weight: normal;"><u><tt>GetScratchpadByte</tt></u></span>===
+
===MatchROM===
Returns a byte from the last read scratchpad at position index.  
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''MatchROM'''
 +
|-
 +
| colspan="2" | Performs a reset followed by the MatchROM code and then the 8-bit ROM code.&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | FamilyCode
 +
|-
 +
| colspan="2" | &nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | SerialNumber
 +
|-
 +
| colspan="2" | &nbsp;
 +
|-
 +
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
 +
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
  
The index byte can go from 0 - 8 to reference the 9 individual scratchpad bytes.
 
  
'''Parameters'''
+
===ReceiveByte===
 +
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReceiveByte'''
 +
|-
 +
| colspan="2" | Receives a byte from the one wire bus a bit at a time&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
  
:[[Variable Types|BYTE]] ''Index''
 
::Select which pad byte to use 0-8
 
  
 +
===ScanBus===
 +
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ScanBus'''
 +
|-
 +
| colspan="2" | Scans the one wire bus to detect all connected devices. Returns the number of one wire devices found.&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
  
'''Return value'''
 
  
:[[Variable Types|BYTE]]
+
===SkipROM===
 +
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SkipROM'''
 +
|-
 +
| colspan="2" | Performs a bus reset and the sends the SkipROM command byte&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
 +
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
  
  
===<span style="font-weight: normal;"><u><tt>GetIDByte</tt></u></span>===
+
===TransmitByte===
Returns byte ectet of the 64-Bit lasered ROM code, 255 on error
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 
+
|-
'''Parameters'''
+
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''TransmitByte'''
:[[Variable Types|BYTE]] ''Device''
+
|-
::Device ID - Range: 0 - NumDevices - 1
+
| colspan="2" | Transmit a byte to the one wire bus a bit at a time&nbsp;
 
+
|-
:[[Variable Types|BYTE]] ''ByteIndex''
+
|-
::Index of the data byte. 0=FamilyCode, 1-6=Serial, 7=CRC
+
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 
+
| width="90%" | Command
 
+
|-
'''Return value'''
+
| colspan="2" | &nbsp;
 
+
|-
:[[Variable Types|BYTE]]
+
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
 
+
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
+
|}
===<span style="font-weight: normal;"><u><tt>Initialise</tt></u></span>===
 
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==
 
==Property reference==
<span style="font-weight: normal;"><u>One Wire Pin</u></span>
 
  
This property is of type ''Single digital pin'' and can be referenced with the variable name ''oo_pin''.
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 
+
|-
I/O pin used to host one wire bus.
+
| width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-prop-icon.png]]
 
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties'''  
<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''.
+
| width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
 
+
| width="90%" | One Wire Pin
Sets the component timing model.
+
|-
 
+
| colspan="2" | I/O pin used to host one wire bus.&nbsp;
Standard is the usual 1-wire timing,
+
|-
 
+
| width="10%" align="center" | [[File:Fc9-type-21-icon.png]]
Overdrive is a high speed 1-wire timing.
+
| width="90%" | Max Devices
 
+
|-
<span style="font-weight: normal;"><u>Max Devices</u></span>
+
| colspan="2" | 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&nbsp;
 
+
|-
This property is of type ''Unsigned integer'' and can be referenced with the variable name ''BufferSize''.
+
| width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]]
 
+
| width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Simulation
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.
+
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
 
+
| width="90%" | API
Default: 8 = 64 Bytes of RAM
+
|-
 +
| colspan="2" | Lists all the current injector components available on the user's panel&nbsp;
 +
|}

Latest revision as of 13:12, 7 February 2023

Author Matrix Ltd
Version 1.4
Category Comms: Interface


One Wire component

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

Component Source Code

Please click here to download the component source project: FC_Comp_Source_One_Wire.fcfx

Please click here to view the component source code (Beta): FC_Comp_Source_One_Wire.fcfx

Detailed description

No detailed description exists yet for this component

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.


Example One Wire comms component being referenced by several specific One Wire device library components.

OneWire.jpg






Macro reference

BusReset

Fc9-comp-macro.png 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 
Fc9-bool-icon.png - BOOL Return


GetDeviceCount

Fc9-comp-macro.png GetDeviceCount
Returns the number of devices found by the last ScanBus operation. 
Fc9-u8-icon.png - BYTE Return


GetIDByte

Fc9-comp-macro.png GetIDByte
Returns byte ectet of the 64-Bit lasered ROM code, 255 on error 
Fc9-u8-icon.png - BYTE Device
Device ID - Range: 0 - NumDevices - 1 
Fc9-u8-icon.png - BYTE ByteIndex
Index of the data byte. 0=FamilyCode, 1-6=Serial, 7=CRC 
Fc9-u8-icon.png - BYTE Return


Initialise

Fc9-comp-macro.png Initialise
Sets up the 1-Wire output pin ready for communications. 
Fc9-void-icon.png - VOID Return


MatchROM

Fc9-comp-macro.png MatchROM
Performs a reset followed by the MatchROM code and then the 8-bit ROM code. 
Fc9-u8-icon.png - BYTE FamilyCode
 
Fc9-u8-icon.png - BYTE SerialNumber
 
Fc9-void-icon.png - VOID Return


ReceiveByte

Fc9-comp-macro.png ReceiveByte
Receives a byte from the one wire bus a bit at a time 
Fc9-u8-icon.png - BYTE Return


ScanBus

Fc9-comp-macro.png ScanBus
Scans the one wire bus to detect all connected devices. Returns the number of one wire devices found. 
Fc9-u8-icon.png - BYTE Return


SkipROM

Fc9-comp-macro.png SkipROM
Performs a bus reset and the sends the SkipROM command byte 
Fc9-void-icon.png - VOID Return


TransmitByte

Fc9-comp-macro.png TransmitByte
Transmit a byte to the one wire bus a bit at a time 
Fc9-u8-icon.png - BYTE Command
 
Fc9-void-icon.png - VOID Return


Property reference

Fc9-prop-icon.png Properties
Fc9-type-5-icon.png One Wire Pin
I/O pin used to host one wire bus. 
Fc9-type-21-icon.png Max Devices
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 
Fc9-conn-icon.png Simulation
Fc9-type-16-icon.png API
Lists all the current injector components available on the user's panel