21.11.2014 Views

STAMP 2 Communications And Control Projects.pdf

STAMP 2 Communications And Control Projects.pdf

STAMP 2 Communications And Control Projects.pdf

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

SERIAL PORT INTERFACING 27<br />

components, but most RS-232 devices also regard a signal close to 0 V as a logic 1. So if<br />

our 5-V logic’s 0 is close to 0 V, it will suffice as an RS-232 logic 1.<br />

The <strong>STAMP</strong> 2 will support this type of “fooling”; you simply program the <strong>STAMP</strong> 2’s<br />

serial output instruction to send inverted serial data. So now when the <strong>STAMP</strong> 2 receives<br />

data from conventional RS-232 sources, it is receiving a ±15-V signal. In order to protect<br />

the <strong>STAMP</strong> 2 from destruction, a 22-k resistor is placed in series with the <strong>STAMP</strong> 2 I/O<br />

line for incoming RS-232 data.<br />

Many projects presented in this book use the alternative <strong>STAMP</strong> 2, which utilizes<br />

MAX232 serial line drivers to get serial data to and from the <strong>STAMP</strong> 2. The baudmode<br />

command is a 16-bit number that specifies all the important characteristics of the serial<br />

transmission, i.e., bit time, data and parity bits, polarity, etc. Table 2-1 illustrates more detail<br />

on decimal baud rate number information and direct versus line driver interfacing. Also<br />

check App. 2 and the <strong>STAMP</strong> 2 programming manual included on the enclosed CD-ROM.<br />

The Serin and Serout <strong>STAMP</strong> 2 serial command lines are typically quite similar in their<br />

appearance. The Serin command to send/receive asynchronous data is represented as Serin<br />

rpin{\fpin},baudmode,{plabel,}{timeout,label,}[inputData], and often the command can be<br />

as simple as Serin rpin,baudmode,[inputData]. The Serout command structure for transmitting<br />

asynchronous data is represented as Serout tpin,baudmode,{pace,}[outputData] or<br />

Serout tpin\fpin,baudmode,{timeout,tlabel,}[outputData]. Often the Serout command can<br />

be as simple as Serout tpin,baudmode,[outputData].<br />

Some typical <strong>STAMP</strong> 2 SERIN commands are shown below.<br />

Serin rpin,baudmode, [inputdata]<br />

In the above example the rpin is the <strong>STAMP</strong> 2 I/O pin that will be receiving serial data.<br />

Baudmode is the setting for the bit rate, data bits, parity, and polarity. The inputdata specifies<br />

what do to with the incoming data—to compare it, ignore it, store it, or convert it from<br />

text to a numeric value, for example.<br />

TABLE 2-1 SINGLE FRAME OF SERIAL DATA—BAUDMODE (Decimal Numbers)<br />

8 BITS 7 BITS 8 BITS 7 BITS<br />

BAUD RATE NO PARITY EVEN PARITY NO PARITY EVEN PARITY<br />

300 19697 27889 3313 11505<br />

600 18030 26222 1646 9838<br />

1200 17197 25389 813 9005<br />

2400 16780 24972 396 8588<br />

4800 16572 24764 188 8380<br />

9600 16468 24660 84 8276<br />

19200 16416 24608 32 8224<br />

38400 16390 24582 6 8198

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!