Component: One Wire (Comms: Interface)

From Flowcode Help
Jump to navigationJump to search


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


To use the example 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.

Single Device

Here is an example program to read a single DS18S20+ one wire temperature sensor device using a 16F1937 device. The DS18S20+ is connected to pin C0 and to display the temperature there is a LCD connected to PortB. FC6 Icon.png Single One Wire Demo

Multiple Devices

Here is an example program to read multiple DS18S20+ one wire temperature sensor devices connected to pin C0 and display the temperature of the selected sensor onto a LCD connected to PortB. Switches connected to pins A0 and A1 allow the currently active sensor to be changed. A0 increases the sensor index, A1 decreases the sensor index. FC6 Icon.png Multiple One Wire Demo

Downloadable macro reference

DS1820_StartConversion

DS1820 device specific function

Commands all sensors to start a temperature conversion

Parameters

This macro has no parameters


Return value

BYTE


ReceiveByte

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

Parameters

This macro has no parameters


Return value

BYTE


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


GetPadByte

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


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

BYTE


ScanBus

Scans the one wire bus to detect all devices

Parameters

This macro has no parameters


Return value

BYTE


GetDeviceCount

Returns the number of detected devices

Parameters

This macro has no parameters


Return value

BYTE


GetIDByte

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

Parameters

BYTE device
BYTE octet


Return value

BYTE


DS1820_ReadScratchpad

Reads the scratchpad of the currently selected device

Parameters

This macro has no parameters


Return value

BYTE


ReadDevice

Reads the temperature of the device at location count in the id array

Parameters

BYTE count


Return value

BYTE


DS1820_GetTemp

Returns the two byte value of the temperature sensor

Parameters

This macro has no parameters


Return value

UINT


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.

CRC Enabled

This property is of type True or false and can be referenced with the variable name crc_en.

Sets the CRC bit based error detection on or off. (cyclic redundancy check)

Label

This property is of type Line of text and can be referenced with the variable name label.

Label to draw on the GUI object for identification

Injector

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

Lists all the current injector components available on the user's panel