\section{1-Wire Unit}

The 1-Wire unit implements the Dallas Semiconductor's 1-Wire protocol, most commonly used to interface smart thermometers (DS18x20). The protocol is explained in section \ref{sec:theory-1wire}. 

This unit implements the ROM Search algorithm that is used to find the unique IDs of all 1-Wire devices connected to the bus. The algorithm can find up to 32 devices in one run; More devices can be found by issuing the SEARCH\_CONTINUE command.

Devices are addressed using their 64-bit (8-byte) identifiers. When only one device is connected, the value 0 may be used and the addressing will be skipped. Its ID may be recovered using the READ\_ADDR command or by the search algorithm.

\subsection{1-Wire Configuration}

\begin{inicode}
[1WIRE:ow@7]
# Data pin
pin=A0
# Parasitic (bus-powered) mode
parasitic=N
\end{inicode}

\subsection{1-Wire Events}

This unit generates no events.

\subsection{1-Wire Commands}

\begin{tabularx}{\textwidth}{p{\fldwcode}Xp{\fldwpld}}
	\toprule
	\textbf{Code} & \textbf{Function} & \textbf{Payload}  \\	
	\midrule	
	
	0 & \flname{CHECK\_PRESENCE}
	Test if there are any devices attached to the bus.
	& \makecell[tl]{
		\fldresp
		\fld{u8} presence detected (0, 1)
	} \\
	
	1 & \flname{SEARCH\_ADDR}
	Start the search algorithm.
	& \makecell[tl]{
		\fldresp
		\fld{u8} should continue (0, 1) \\
		\fld{u64[]} device addresses
	} \\

	2 & \flname{SEARCH\_ALARM}
	Start the search algorithm, finding only devices in an alarm state.
	& \makecell[tl]{
		\fldresp
		\fld{u8} should continue (0, 1) \\
		\fld{u64[]} device addresses
	} \\

	3 & \flname{SEARCH\_CONTINUE}
	Continue a previously started search
	& \makecell[tl]{
		\fldresp
		\fld{u8} should continue (0, 1) \\
		\fld{u64[]} device addresses
	} \\

	4 & \flname{READ\_ADDR}
	Read a device address (single device only)
	& \makecell[tl]{
		\fldresp
		\fld{u64} device address
	} \\
	
	10 & \flname{WRITE} 
	Write bytes to a device.
	& \makecell[tl]{
		\fldreq
		\fld{u64} device address \\
		\fld{u8[]} bytes to write
	} \\
	
	11 & \flname{READ}
	Write a request and read response.
	& \makecell[tl]{
		\fldreq
		\fld{u64} device address \\
		\fld{u16} read length \\
		\fld{u8} verify checksum (0, 1) \\
		\fld{u8[]} request bytes
	} \\

	20 & \flname{POLL\_FOR\_1} 
	Wait for a READY status, used by DS18x20. 
	Not available in parasitic mode. 
	Responds with SUCCESS after all devices are ready.
	&  \\
	\bottomrule
\end{tabularx}


