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/OWIN.htm

432 lines
23 KiB
HTML
Raw Normal View History

<?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>OWIN</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">OWIN</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">OWIN</span> <![CDATA[ ]]><i>Pin</i>,<i> Mode</i>, [<i>InputData</i>]</p>
<h2>Function</h2>
<p>Receive data from 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">OWIN</span> command and will be set to input mode
by the end of the <span class="keyword_in_text">OWIN</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 speed. See explanation below.</li>
<li value="3"><b><i>InputData</i></b> is a list of variables and modifiers that tells
<span class="keyword_in_text">OWIN</span> what to do with incoming data. <span class="keyword_in_text">OWIN</span> can store data in a
variable or array, interpret numeric text (decimal, binary, or hex) and store
the corresponding value in a variable, wait for a fixed or variable sequence
of bytes, or ignore a specified number of bytes. These actions can be combined
in any order in the <i>InputData</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">Receive 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
resist0r.</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
<td align="center" colspan="1">
<p colspan="1" align="center"><a href="OWOUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">OWOUT</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">OWIN</span> command
allows the BASIC Stamp to receive data from a 1-Wire device.</p>
<p>The following is an example of the <span class="keyword_in_text">OWIN</span> command:</p><pre class="BScode" xml:space="preserve">
result VAR Byte
Main:
OWIN 0, 1, [result]
STOP
</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 receive one byte and store it in the variable result. </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>
<h3><i>Mode</i> Format bits</h3>
<table width="35%" cellpadding="4" cellspacing="0" border="1">
<tr bgcolor="#CFCFCF">
<td width="50" align="center">Bit</td>
<td width="200" align="center">Function</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">0</td>
<td>Front-End Reset<br></br>• 0 = No reset <br></br>• 1 = Generate reset before data</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">1</td>
<td>Back-End Reset<br></br>• 0 = No reset <br></br>• 1 = Generate reset after data</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">2</td>
<td>Bit / Byte Transfer<br></br>• 0 = Byte <br></br>• 1 = Bit</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">3</td>
<td>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 Mode. In many
cases, however, when using the <span class="keyword_in_text">OWIN</span> command, <i>Mode</i> should be set for
either No Reset (to receive data from a transaction already started by a <span class="keyword_in_text">OWOUT</span>command) or a Back-End Reset (to terminate the session after data is received).
This may vary due to device and application requirements, however.</p>
<p>When using the Bit (rather than Byte) mode of data transfer, all variables in
the <i>InputData</i> argument will only receive one bit. For example, the following
code could be used to receive two bits using this mode:</p><pre class="BScode" xml:space="preserve">
bitOne VAR Bit
bitTwo VAR Bit
Main:
OWIN 0, 6, [bitOne, bitTwo]
STOP
</pre>
<p class="PlainText">In the code above, we chose the value "6" for <i>Mode</i>. This sets Bit transfer
and Back-End Reset modes. Also, we could have chosen to make the bitOne and bitTwo
variables each a byte in size, but they still would only have received one bit each
in the <span class="keyword_in_text">OWIN</span> command (due to the <i>Mode</i> selected).</p>
<p class="PlainText">The <span class="keyword_in_text">OWIN</span> command's <i>InputData</i> argument is similar to the <b>SERIN</b>command's <i>InputData</i> argument. This means data can be received as ASCII
character values, decimal, hexadecimal and binary translations and string data as
in the examples below. (Assume a 1-Wire device is used and that
it transmits the string, "Value: 3A:101" every time it receives a Front-End Reset
pulse).</p><pre class="BScode" xml:space="preserve">
value VAR Byte(13)
Main:
OWIN 0, 1, [value] ' receive ASCII code for "V"
OWIN 0, 1, [DEC value] ' receive the number 3
OWIN 0, 1, [HEX value] ' receive the number $3A
OWIN 0, 1, [BIN value] ' receive the number %101
OWIN 0, 1, [STR value\13] ' receive the string "Value: 3A:101"
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">OWIN</span> command. See the <a href="SERIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SERIN</a> command 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="150">Special Formatter</td>
<td>Action</td>
</tr>
<tr>
<td align="center">STR ByteArray \L {\E}</td>
<td>Input a character string of length L into an array. If specified, an end
character E causes the string input to end before reaching length L.
Remaining bytes are filled with 0s (zeros).</td>
</tr>
<tr>
<td align="center">WAITSTR ByteArray {\L}</td>
<td>Wait for a sequence of bytes matching a string stored in an array variable,
optionally limited to L characters. If the optional L argument is left off,
the end of the array-string must be marked by a byte containing a zero (0).</td>
</tr>
<tr>
<td align="center">SKIP Length</td>
<td>Ignore Length bytes of characters.</td>
</tr>
<tr>
<td align="center">SPSTR Length</td>
<td>Buffer Length bytes (up to 126) of serial characters to Scratchpad RAM,
starting at location 0. Use <a href="GET.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">GET</a> to retrieve the
characters.</td>
</tr>
</table>
<p>&#160;</p>
<p>
<img src="../../graphics/bs2all_inline.gif" border="0" />
</p>
<table width="100%" cellpadding="4" cellspacing="0" border="1">
<tr bgcolor="#CFCFCF" align="center" valign="top">
<td width="15%">Conversion Formatter</td>
<td width="45%">Type of Number</td>
<td width="30%">Numeric Characters Accepted</td>
<td width="10%">Notes</td>
</tr>
<tr align="center">
<td>DEC{1..5}</td>
<td>Decimal, optionally limited to 1 - 5 digits</td>
<td>0 through 9</td>
<td>1</td>
</tr>
<tr align="center">
<td>SDEC{1..5}</td>
<td>Signed decimal, optionally limited to 1 - 5 digits</td>
<td>-, 0 through 9</td>
<td>1,2</td>
</tr>
<tr align="center">
<td>HEX{1..4}</td>
<td>Hexadecimal, optionally limited to 1 - 4 digits</td>
<td>0 through 9, A through F</td>
<td>1,3</td>
</tr>
<tr align="center">
<td>SHEX{1..4}</td>
<td>Signed hexadecimal, optionally limited to 1 - 4 digits </td>
<td>-, 0 through 9, A through F</td>
<td>1,2,3</td>
</tr>
<tr align="center">
<td>IHEX{1..4}</td>
<td>Indicated hexadecimal, optionally limited to 1 - 4 digits</td>
<td>$, 0 through 9, A through F</td>
<td>1,3,4</td>
</tr>
<tr align="center">
<td>ISHEX{1..4}</td>
<td>Signed, indicated hexadecimal, optionally limited to 1 - 4 digits</td>
<td>-, $, 0 through 9, A through F</td>
<td>1,2,3,4</td>
</tr>
<tr align="center">
<td>BIN{1..16}</td>
<td>Binary, optionally limited to 1 - 16 digits</td>
<td>0, 1</td>
<td>1</td>
</tr>
<tr align="center">
<td>SBIN{1..16}</td>
<td>Signed binary, optionally limited to 1 - 16 digits</td>
<td>-, 0, 1</td>
<td>1,2</td>
</tr>
<tr align="center">
<td>IBIN{1..16}</td>
<td>Indicated binary, optionally limited to 1 - 16 digits</td>
<td>%, 0, 1</td>
<td>1,4</td>
</tr>
<tr align="center">
<td>ISBIN{1..16}</td>
<td>Signed, indicated binary, optionally limited to 1 - 16 digits</td>
<td>-, %, 0, 1</td>
<td>1,2,4</td>
</tr>
<tr align="center">
<td>NUM</td>
<td>Generic numeric input; hex or binary number must be indicated</td>
<td>$, %, 0 through 9, A through F</td>
<td>1,3,4</td>
</tr>
<tr align="center">
<td>SNUM</td>
<td>Similar to NUM with value treated as signed with range -32768 to +32767</td>
<td>-, $, %, 0 through 9, A through F</td>
<td>1,2,3,4</td>
</tr>
</table>
<ol>
<li value="1">All numeric conversions will continue to accept new data until receiving
either the specified number of digits (ex: three digits for DEC3) or a
non-numeric character.</li>
<li value="2">To be recognized as part of a number, the minus sign (-) must immediately
precede a numeric character. The minus sign character occurring in non-numeric
text is ignored and any character (including a space) between a minus and a
number causes the minus to be ignored.</li>
<li value="3">The hexadecimal formatters are not case-sensitive; "a" through "f" means
the same as "A" through "F".</li>
<li value="4">Indicated hexadecimal and binary formatters ignore all characters, even
valid numerics, until they receive the appropriate prefix ($ for hexadecimal,
% for binary). The indicated formatters can differentiate between text and
hexadecimal (ex: ABC would be interpreted by HEX as a number but IHEX would
ignore it unless expressed as $ABC). Likewise, the binary version can
distinguish the decimal number 10 from the binary number %10. A prefix
occurring in non-numeric text is ignored, and any character (including a space)
between a prefix and a number causes the prefix to be ignored. Indicated, signed
formatters require that the minus sign come before the prefix, as in -$1B45.</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>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" 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 Skip 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">OWIN</span> command will read data at this
point in the transaction. A read is accomplished by generating a brief low-pulse
and sampling the line within 15 ms of the falling edge of the pulse. This is called
a "Read Slot." The figure below shows typical Read Slots performed by the BASIC
Stamp. See the <a href="OWOUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">OWOUT</a> command for information on Write Slots.</p>
<center>
<img src="../../graphics/ow_readslots.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>