This repository has been archived on 2024-09-22. You can view files and clone it, but cannot push or open issues or pull requests.
pbi-ide/help/BasicStampHelp/Content/LanguageTopics/Commands/OWOUT.htm

401 lines
21 KiB
HTML

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" MadCap:lastBlockDepth="6" MadCap:lastHeight="94" MadCap:lastWidth="853" MadCap:disableMasterStylesheet="true" MadCap:tocPath="" MadCap:InPreviewMode="false" MadCap:PreloadImages="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" lang="en-us" xml:lang="en-us" MadCap:PathToHelpSystem="../../../" MadCap:HelpSystemFileName="Default.xml" MadCap:SearchType="Stem">
<head><title>OWOUT</title>
<link href="../../SkinSupport/MadCap.css" rel="stylesheet" />
<link href="../../Resources/Stylesheets/BSE_Help.css" rel="stylesheet" />
<script src="../../SkinSupport/MadCapAll.js" type="text/javascript">
</script>
</head>
<body>
<h1 class="code">OWOUT</h1>
<div class="ImagePlusCaption">
<div class="Col2">
<p>
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
</p>
</div>
<p style="text-align: right;"><a href="../ExampleTopics/OwinOwoutEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">OWIN / OWOUT Example</a>
</p>
<p>&#160;</p>
</div>
<p class="clear">&#160;</p>
<p>&#160;</p>
<p class="PlainText">Syntax: <span class="keyword_in_text">OWOUT</span> <![CDATA[ ]]><i>Pin</i>,<i> Mode</i>, [<i>OutputData</i>]</p>
<h2>Function</h2>
<p class="PlainText">Send data to a device using the Maxim/Dallas Semiconductor 1-Wire<sup>®</sup>protocol.</p>
<ul>
<li value="1"><b><i>Pin</i></b> is a variable/constant/expression (0 - 15) that specifies
which I/O pin to use. 1-Wire devices require only one I/O
pin (called DQ) to communicate. This I/O pin will be toggled between output
and input mode during the <span class="keyword_in_text">OWOUT</span> command and will be set to input mode
by the end of the <span class="keyword_in_text">OWOUT</span> command.</li>
<li value="2"><b><i>Mode</i></b> is a variable/constant/expression (0 - 15) indicating
the mode of data transfer. The <i>Mode</i> argument controls placement of
reset pulses (and detection of presence pulses) as well as byte vs. bit input
and normal vs. high<sup></sup> speed. See explanation below.</li>
<li value="3"><b><i>OutputData</i></b> is a list of variables and modifiers that tells
<span class="keyword_in_text">OWOUT</span> how to format outgoing data. <span class="keyword_in_text">OWOUT</span> can transmit individual
or repeating bytes, convert values into decimal, hexadecimal or binary text
representations, or transmit strings of bytes from variable arrays. These
actions can be combined in any order in the <i>OutputData</i> list.</li>
</ul>
<h2>Quick Facts</h2>
<table width="100%" cellpadding="4" cellspacing="0" border="1">
<tr bgcolor="#CFCFCF">
<td width="20%" align="center">&#160;</td>
<td width="80%" align="center">BS2p, BS2pe, and BS2px</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">Transmission Rate</td>
<td>Approximately 20 kbits/sec (low speed, not including reset pulse)</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">Special Notes</td>
<td>The DQ pin (specified by <i>Pin</i>) must have a 4.7 kΩ pull-up
resister.</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
<td align="center" colspan="1">
<p colspan="1" align="center"><a href="OWIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">OWIN</a>
</p>
</td>
</tr>
</table>
<h2>Explanation</h2>
<p class="PlainText">The 1-Wire protocol is a form of asynchronous serial communication developed by
Maxim/Dallas Semiconductor. It only requires one I/O pin and that pin can
be shared between multiple 1-Wire devices. The <span class="keyword_in_text">OWOUT</span>
command allows the BASIC Stamp to send data to a 1-Wire device.</p>
<p class="PlainText">The following is an example of the <span class="keyword_in_text">OWOUT</span> command:</p><pre class="BScode" xml:space="preserve">
OWOUT 0, 1, [$4E]
</pre>
<p class="PlainText">This code will transmit a "reset" pulse to a 1-Wire device
(connected to I/O pin 0) and then will detect the device's "presence" pulse and
then transmit one byte (the value $4E).</p>
<p class="PlainText">The <i>Mode</i> argument is used to control placement of reset pulses (and
detection of presence pulses) and to designate byte vs. bit input and normal vs.
high speed<sup></sup>. The tables below show the meaning of each of the
four bits of <i>Mode</i> and some of the 16 possible values and their effect. </p>
<table align="center" width="35%" cellpadding="4" cellspacing="0" border="1">
<tr bgcolor="#CFCFCF">
<td width="50" style="text-align: center;">Bit</td>
<td width="200" style="text-align: center;">Function</td>
</tr>
<tr>
<td bgcolor="#CFCFCF" style="text-align: center;">0</td>
<td style="text-align: left;">Front-End Reset<br></br>• 0 = No reset <br></br>• 1 = Generate reset
before data</td>
</tr>
<tr>
<td bgcolor="#CFCFCF" style="text-align: center;">1</td>
<td style="text-align: left;">Back-End Reset<br></br>• 0 = No reset <br></br>• 1 = Generate reset
after data</td>
</tr>
<tr>
<td bgcolor="#CFCFCF" style="text-align: center;">2</td>
<td style="text-align: left;">Bit / Byte Transfer<br></br>• 0 = Byte <br></br>• 1 = Bit</td>
</tr>
<tr>
<td bgcolor="#CFCFCF" style="text-align: center;">3</td>
<td style="text-align: left;">Low / High Speed<sup></sup><br></br>• 0 = Low <br></br>• 1 = High</td>
</tr>
</table>
<p>&#160;</p>
<table width="35%" cellpadding="4" cellspacing="0" border="1">
<tr bgcolor="#CFCFCF" align="center">
<td width="50">Mode</td>
<td>Effect</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">0</td>
<td>No Reset, Byte mode, Low speed</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">1</td>
<td>Reset before data, Byte mode, Low speed</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">2</td>
<td>Reset after data, Byte mode, Low speed</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">3</td>
<td>Reset before and after data, Byte mode, Low speed</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">4</td>
<td>No Reset, Bit mode, Low speed</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">5</td>
<td>Reset before data, Bit mode, Low speed</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">6</td>
<td>Reset after data, Bit mode, Low speed</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">7</td>
<td>Reset before and after data, Bit mode, Low speed</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">8</td>
<td>No Reset, Byte mode, High speed<sup></sup></td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">9</td>
<td>Reset before data, Byte mode, High speed<sup></sup></td>
</tr>
</table>
<p><sup></sup> The BS2pe is not capable of High Speed transfers.</p>
<p>&#160;</p>
<p class="PlainText">The proper value for <i>Mode</i> depends on the 1-Wire device
and the portion of the communication you're working on. Please consult the data
sheet for the device in question to determine the correct value for <i>Mode</i>.
In many cases, however, when using the <span class="keyword_in_text">OWOUT</span> command, <i>Mode</i> should
be set for a Front-End Reset (to initialize the transaction). This may vary due
to device and application requirements, however.</p>
<p class="PlainText">When using the Bit (rather than Byte) mode of data transfer, all variables in
the <i>OutputData</i> argument will only transmit one bit. For example, the
following code could be used to send two bits using this mode:</p><pre class="BScode" xml:space="preserve">
bitOne VAR Bit
bitTwo VAR Bit
Init:
bitOne = 0
bitTwo = 1
Main:
OWOUT 0, 5, [bitOne, bitTwo]
STOP
</pre>
<p class="PlainText">In the code above, we chose the value "5" for <i>Mode</i>. This sets Bit transfer
and Front-End Reset modes. Also, we could have chosen to make the bitOne and
bitTwo variables each a byte in size, but the BASIC Stamp would still only use the
their lowest bit (Bit0) as the value to transmit in the <span class="keyword_in_text">OWOUT</span> command (due
to the <i>Mode</i> we chose).</p>
<p class="PlainText">The <span class="keyword_in_text">OWOUT</span> command's <i>OutputData</i> argument is similar to the <b>DEBUG</b>
and <b>SEROUT</b> command's <i>OutputData</i> argument. This means data can be
sent as literal text, ASCII character values, repetitive values, decimal, hexadecimal
and binary translations and string data as in the examples below.</p><pre class="BScode" xml:space="preserve">
value VAR Byte
Init:
value = 65
Main:
OWOUT 0, 1, [value] ' send ASCII character "A"
OWOUT 0, 1, [REP value\5] ' send "A" 5x, ie: "AAAAA"
OWOUT 0, 1, [DEC value] ' send "6" and "5"
OWOUT 0, 1, [HEX value] ' send "4" and "1"
OWOUT 0, 1, [BIN value] ' send "1000001"
STOP
</pre>
<p class="PlainText">The tables below list all the available special formatters and conversion
formatters available to the <span class="keyword_in_text">OWOUT</span> command. See the <a href="DEBUG.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">DEBUG</a>
&#160; and <a href="SEROUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SEROUT</a> commands
for additional information and examples of their use.</p>
<table width="100%" cellpadding="4" cellspacing="0" border="1">
<tr bgcolor="#CFCFCF" align="center" valign="top">
<td width="20%">Special Formatter</td>
<td width="80%">Action</td>
</tr>
<tr>
<td align="center">?</td>
<td>Displays "symbol = x' + carriage return; where x is a number. Default
format is decimal, but may be combined with conversion formatters (ex: BIN
? x to display "x = binary_number").</td>
</tr>
<tr>
<td align="center">ASC ?</td>
<td>Displays "symbol = 'x'" + carriage return; where x is an ASCII
character.</td>
</tr>
<tr>
<td align="center">STR ByteArray {\L}</td>
<td>Send character string from an array. The optional \L argument can be
used to limit the output to L characters, otherwise, characters will be
sent up to the first byte equal to 0 r the end of RAM space is reached.</td>
</tr>
<tr>
<td align="center">REP Byte\L</td>
<td>Send a string consisting of Byte repeated L times (ex: REP "X"\10 sends
"XXXXXXXXXX").</td>
</tr>
</table>
<p>&#160;</p>
<table width="100%" cellpadding="4" cellspacing="0" border="1">
<tr bgcolor="#CFCFCF" align="center" valign="top">
<td width="20%">Conversion Formatter</td>
<td width="70%">Type of Number</td>
<td width="10%">Notes</td>
</tr>
<tr align="center">
<td>DEC{1..5}</td>
<td align="left">Decimal, optionally fixed to 1 - 5 digits</td>
<td>1</td>
</tr>
<tr align="center">
<td>SDEC{1..5}</td>
<td align="left">Signed decimal, optionally fixed to 1 - 5 digits</td>
<td>1,2</td>
</tr>
<tr align="center">
<td>HEX{1..4}</td>
<td align="left">Hexadecimal, optionally fixed to 1 - 4 digits</td>
<td>1</td>
</tr>
<tr align="center">
<td>SHEX{1..4}</td>
<td align="left">Signed hexadecimal, optionally fixed to 1 - 4 digits </td>
<td>1,2</td>
</tr>
<tr align="center">
<td>IHEX{1..4}</td>
<td align="left">Indicated hexadecimal, optionally fixed to 1 - 4 digits</td>
<td>1</td>
</tr>
<tr align="center">
<td>ISHEX{1..4}</td>
<td align="left">Signed, indicated hexadecimal, optionally fixed to 1 - 4
digits ($ prefix)</td>
<td>1,2</td>
</tr>
<tr align="center">
<td>BIN{1..16}</td>
<td align="left">Binary, optionally fixed to 1 - 16 digits</td>
<td>1</td>
</tr>
<tr align="center">
<td>SBIN{1..16}</td>
<td align="left">Signed binary, optionally fixed to 1 - 16 digits</td>
<td>1,2</td>
</tr>
<tr align="center">
<td>IBIN{1..16}</td>
<td align="left">Indicated binary, optionally fixed to 1 - 16 digits</td>
<td>1</td>
</tr>
<tr align="center">
<td>ISBIN{1..16}</td>
<td align="left">Signed, indicated binary, optionally fixed to 1 - 16 digits</td>
<td>1,2</td>
</tr>
</table>
<ol>
<li value="1">Fixed-digit formatters like DEC4 will pad the number with leading 0s if
necessary; ex: DEC4 65 sends 0065. If a number is larger than the specified
number of digits, the leading digits will be dropped; ex: DEC4 56422 sends
6422.</li>
<li value="2">Signed modifiers work under two's complement rules.</li>
</ol>
<h3>The 1-Wire Protocol Format</h3>
<p class="PlainText">The 1-Wire protocol has a well-defined standard for transaction
sequences. Every transaction sequence consists of four parts: 1) Initialization,
2) ROM Function Command, 3) Memory Function Command, and 4) Transaction/Data.
Additionally, the ROM Function Command and Memory Function Command are always 8
bits wide (1 byte in size) and is sent least-significant-bit (LSB) first.
</p>
<p class="PlainText">The Initialization part consists of a reset pulse (generated by the master)
and will be followed by a presence pulse (generated by all slave devices). The
figure below details the reset pulse generated by the BASIC Stamp and a typical
presence pulse generated by a 1-Wire slave, in response.</p>
<center>
<img src="../../graphics/ow_pulses.gif" width="389" height="223" border="0">
</img>
</center>
<p>&#160;</p>
<p class="PlainText">This reset pulse is controlled by the lowest two bits of the <i>Mode</i>
argument in the <span class="keyword_in_text">OWIN</span> command. It can be made to appear before the ROM
Function Command (ex: Mode = 1), after the Transaction/Data portion (ex: Mode
= 2), before and after the entire transaction (ex: Mode = 3) or not at all (ex:
Mode = 0). See the section on <i>Mode</i>, above, for more information.</p>
<p class="PlainText">Following the Initialization part is the ROM Function Command. The ROM Function
Command is used to address the desired 1-Wire device. The table
below shows common ROM Function Commands. If only a single 1-Wire
device is connected, the Match ROM command can be used to address it. If more than
one 1-Wire device is attached, the BASIC Stamp will ultimately
have to address them individually using the Match ROM command.</p>
<table width="100%" cellpadding="4" cellspacing="0" border="1">
<tr bgcolor="#CFCFCF" align="center" valign="top">
<td width="100">Command</td>
<td width="100">Value (HEX)</td>
<td>Action</td>
</tr>
<tr>
<td align="center">Read ROM</td>
<td align="center">$33</td>
<td>Reads the 64-bit ID of the 1-Wire device. This command
can only be used if there is a single 1-Wire device on the
line.</td>
</tr>
<tr>
<td align="center">Match ROM</td>
<td align="center">$55</td>
<td>This command, followed by a 64-bit ID, allows the BASIC Stamp to address
a specific 1-Wire device.</td>
</tr>
<tr>
<td align="center">Skip ROM</td>
<td align="center">$CC</td>
<td>Address a 1-Wire device without its 64-bit ID. This
command can only be used if there is a single 1-Wire device
on the line.</td>
</tr>
<tr>
<td align="center">Search ROM</td>
<td align="center">$F0</td>
<td>Reads the 64-bit IDs of all the 1-Wire devices on the
line. A process of elimination is used to distinguish each unique device.</td>
</tr>
</table>
<p>&#160;</p>
<p class="PlainText">The third part, the Memory Function Command, allows the BASIC Stamp to address
specific memory locations, or features, of the 1-Wire device.
Refer to the 1-Wire device's data sheet for a list of the available
Memory Function Commands.</p>
<p class="PlainText">Finally, the Transaction/Data section is used to read or write data to the
1-Wire device. The <span class="keyword_in_text">OWOUT</span> command will write data at this
point in the transaction. A write is accomplished by generating a low-pulse of
a varying width to indicate a 0 or a 1. This is called a "Write Slot" and must be
at least 60 us wide. The figure below shows typical Write Slots performed by the
BASIC Stamp. See the <a href="OWIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">OWIN</a> command for information on Read
Slots.</p>
<center>
<img src="../../graphics/ow_writeslots.gif" border="0" />
</center>
<div class="Col2">
<div class="MasterFoot">
<p MadCap:conditions="BSEconditions.BSEWebHelp (Primary)-INCLUDE"><a href="../../HomeTopics/HomePage.htm">Go to Welcome page</a>
</p>
</div>
</div>
<div class="Col2">
<div class="MasterFoot">
<p style="text-align: right;"><span class="ContactInfoProjectName">BASIC Stamp Help</span> <![CDATA[ ]]><span class="ContactInfoVersion#">Version 2.5.4</span> <![CDATA[ ]]></p>
<p style="text-align: right;">Copyright ©&#160;<span class="ContactInfoCompanyName">Parallax Inc.</span></p>
<p style="text-align: right;"><span class="SystemShortDate">8/8/2012</span>
</p>
</div>
</div>
<script type="text/javascript">/* <![CDATA[ */
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-285614-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
/* ]]> */</script>
<script type="text/javascript" src="../../SkinSupport/MadCapBodyEnd.js">
</script>
</body>
</html>