Revision: 1602
Author: sebastien.lelong
Date: Mon Jan 18 01:03:57 2010
Log: corrected few typos, added links
http://code.google.com/p/jallib/source/detail?r=1602

Modified:
 /trunk/doc/dita/tutorials/tutorial_serial_communication.xml

=======================================
--- /trunk/doc/dita/tutorials/tutorial_serial_communication.xml Sun Jan 17 23:35:40 2010 +++ /trunk/doc/dita/tutorials/tutorial_serial_communication.xml Mon Jan 18 01:03:57 2010
@@ -1,6 +1,6 @@
 <?xml version='1.0' encoding='UTF-8'?>
<!-- This document was created with Syntext Serna Free. --><!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd" []>
-<topic id="template_id">
+<topic id="serial_comms">
   <title>Serial Port &amp; RS-232 for communication</title>
   <prolog>
     <author>Matthew Schinkel</author>
@@ -10,23 +10,23 @@
<p id="firstcontent">In this tutorial we are going to learn how use TX &amp; RX pins for serial communication to your PC, and also learn communicate with another PIC or external device via RS-232.</p>
     <section>
       <title>What is a serial port?</title>
- <p>You may have forgotten about this important part of history &quot;The serial port&quot;. You have forgotten because you have been too up-to-date on all the new technologies such as USB and Blue Tooth, but you have left the good old technologies in the past. Well, now it&apos;s time to put that funny looking port on the back of your PC to some good use! If you don&apos;t have a serial port on your PC, you can get a USB to serial converter/adapter.</p> + <p>You may have forgotten about this important part of history &quot;The serial port&quot;. You have forgotten because you have been too up-to-date on all the new technologies such as USB and Bluetooth, but you have left the good old technologies in the past. Well, now it&apos;s time to put that funny looking port on the back of your PC to some good use! If you don&apos;t have a serial port on your PC, you can get a USB to serial converter/adapter.</p>
       <image href="images/serial_communication_pinout.jpg"/>
- <p>At one time, there where a wide range of devices that used the serial port such as a mouse, keyboard, a old GPS, modems and other networking.</p> - <p>In our case, we will use a serial port to send data to our PC, or to send data a second PIC. I find it most useful for troubleshooting my code, and for sending other readable information to my PC without the use of additional hardware such as a LCD. LCD&apos;s &amp; display&apos;s can be an expensive addition to your circuit.</p> + <p>At one time, there was a wide range of devices that used the serial port such as a mouse, keyboard, old GPS, modems and other networking.</p> + <p>In our case, we will use a serial port to send data to our PC, or to send data a second PIC. I find it most useful for troubleshooting my code, and for sending other readable information to my PC without the use of additional hardware such as a LCD. LCDs &amp; displays can be an expensive addition to your circuit.</p>
     </section>
     <section>
       <title>What is RS-232?</title>
- <p>RS-232 is the data transfer standard used on serial ports. Basically this is composed of one start bit, some data bits, parity bit, and one or two stop bits. The transfer speed as well as the number of start, stop and data bits must match for both the transmitter and receiver. We will not need to cover the way in witch it is transferred since the PIC does it for us. We will only need to know the following: </p> + <p>RS-232 is the data transfer standard used on serial ports. Basically this is composed of one start bit, some data bits, parity bit, and one or two stop bits. The transfer speed as well as the number of start, stop and data bits must match for both the transmitter and receiver. We will not need to cover the way in which it is transferred since the PIC does it for us. We will only need to know the following: </p>
       <p>1. The number of start bits (always 1)</p>
       <p>2. The Parity (usually no parity)</p>
       <p>3. The number of data bits (usually 8)</p>
       <p>4. The number of stop bits (1 or 2)</p>
       <p>5. The data transmission speed</p>
       <p>6. The port number on your PC</p>
- <p>You will be able to choose the transmission speed your self. The Jallib library we will be using will use 1 start bit, 8 data bits, no parity, and 1 stop bit. Your other device, such as your PC will also need to know this information.</p> + <p>You will be able to choose the transmission speed yourself. The Jallib library we will be using will use 1 start bit, 8 data bits, no parity, and 1 stop bit. Your other device, such as your PC will also need to know this information.</p>
     </section>
- <section><title>What do I need?</title>In the first part of this tutorial I will show you how to hook your serial port up to your PC. I will show you how to connect it to another PIC later on in this tutorial. I feel that connectivity to your PC is quite important. You will need:<p>1. A PIC that has TX and RX Pin names. Most PIC&apos;s have them. Check your pinout diagram in the PIC&apos;s datasheet.</p><image href="images/serial_communication_16f877_pinout.jpg"/><p>2. A serial port board. You can buy one on the net, or build your own. <xref href="tutorial_serial_port_board.xml">See Here</xref> for more information. A serial port board is needed for voltage conversion. Serial ports output voltages up to 12v and go lower then 0v.</p><image href="images/serial_communication_board_1.jpg"/><image href="images/serial_communication_board_2.jpg"/><image href="images/serial_communication_board_3.jpg"/><p>3. A regular RS-232 Cable (make sure it is not a null modem cable, they look the same). You can check what type of cable you have with your multimeter. Put your multimeter on each pin of your cable starting with pin 1. Check for a zero ohm reading. This will check that the pins are the same at both ends. Null modem cables have some pins crossed.</p><image href="images/serial_communication_cable.jpg"/><image href="images/serial_communication_usb.jpg"/></section> + <section><title>What do I need?</title>In the first part of this tutorial I will show you how to hook your serial port up to your PC. I will show you how to connect it to another PIC later on in this tutorial. I feel that connectivity to your PC is quite important. You will need:<p>1. A PIC that has TX and RX Pin names. Most PIC&apos;s have them. Check your pinout diagram in the PIC&apos;s datasheet.</p><image href="images/serial_communication_16f877_pinout.jpg"/><p>2. A serial port board. You can buy one on the net, or build your own. <xref href="tutorial_serial_port_board.xml">See Here</xref> for more information. A serial port board is needed for voltage conversion. Serial ports output voltages up to 12v and go lower than 0v.</p><image href="images/serial_communication_board_1.jpg"/><image href="images/serial_communication_board_2.jpg"/><image href="images/serial_communication_board_3.jpg"/><p>3. A regular RS-232 Cable (make sure it is not a null modem cable, they look the same). You can check what type of cable you have with your multimeter. Put your multimeter on each pin of your cable starting with pin 1. Check for a zero ohm reading. This will check that the pins are the same at both ends. Null modem cables have some pins crossed.</p><image href="images/serial_communication_cable.jpg"/><image href="images/serial_communication_usb.jpg"/></section>
     <section>
       <title>Build your circuit</title>
<p>The circuit will be quite simple, you can take your blink a led circuit, and attach your serial port board. Here&apos;s a schematic with 16F877. We will be using the TX and RX pins:</p>
@@ -47,16 +47,16 @@
<image href="images/serial_communication_realterm_port.jpg" width="400" otherprops="clickable"/> <p>Now press &quot;Open&quot; in RealTerm and turn on your circuit. If you now see &quot;Hello serial world......&quot; showing in within RealTerm on your PC, you are able to receive data. </p> <image href="images/serial_communication_realterm_hello.jpg" width="400" otherprops="clickable"/> - <p>If your circuit doesn&apos;t work, your serial port board may have TX and RX switched (you can try switching your TX/RX wires around), or you may have selected the wrong port number, some PC&apos;s have more then one serial port.</p> - <p>Now click on RealTerm&apos;s &quot;send&quot; tab, type in the number &quot;65&quot; in the first box and press &quot;Send Numbers&quot;. If it sent ok, the PIC will echo this value back to you. You will see the ascii character &quot;A&quot;, which is the same as decimal 65. You can see a full ascii chart at asciitable.com. </p> + <p>If your circuit doesn&apos;t work, your serial port board may have TX and RX switched (you can try switching your TX/RX wires around), or you may have selected the wrong port number, some PCs have more than one serial port.</p> + <p>Now click on RealTerm&apos;s &quot;send&quot; tab, type in the number &quot;65&quot; in the first box and press &quot;Send Numbers&quot;. If it sent ok, the PIC will echo this value back to you. You will see the ASCII character &quot;A&quot;, which is the same as decimal 65. You can see a full ASCII chart at <xref href="http://asciitable.com"; format="html">asciitable.com</xref>. </p> <image href="images/serial_communication_realterm_send.jpg" width="400" otherprops="clickable"/> - <p>Now please change your RealTern settings to receive decimal numbers by clicking on the &quot;Display&quot; tab, and choos &quot;int8&quot; under &quot;Display As&quot; at the left side. You will now continuously see the number &quot;46 come in, and try sending the number &quot;65&quot; again. You will get the same number back on your screen.</p> + <p>Now please change your RealTerm settings to receive decimal numbers by clicking on the &quot;Display&quot; tab, and choose &quot;int8&quot; under &quot;Display As&quot; at the left side. You will now continuously see the number &quot;46&quot; come in, and try sending the number &quot;65&quot; again. You will get the same number back on your screen.</p>
       <p>int8 - shows integer numbers in RealTerm</p>
       <p>Ascii - shows ascii text</p>
       <p>Hex[space] - shows hex numbers with a space between each</p>
<image href="images/serial_communication_realterm_65.jpg" width="400" otherprops="clickable"/>
     </section>
-    <section>
+    <section id="pic2pc">
       <title>Write code to send data from PIC to PC</title>
<p>Since this is one of the first circuits you will be building, I will try to give you detailed information so you can get some programming experience. We will continue with your code from &quot;Blink a led&quot;. We will modify it to send data to your PC, Here&apos;s your original code:</p>
       <codeblock>include 16f877a                    -- target PICmicro
@@ -83,12 +83,12 @@
 end loop
 --</codeblock>
<p>First we need to add serial functionality, I got the following code from 16f877a_serial_hardware.jal</p>
-      <codeblock>-- ok, now setup serial;@jallib section serial
+      <codeblock>-- ok, now setup serial;
 const serial_hw_baudrate = 115_200
 include serial_hardware
 serial_hw_init()</codeblock>
- <p>So, now copy and past this into your code, I would put it somewhere after the line &quot;enable_digital_io&quot;, and somewhere before your main program which starts at &quot;forever loop&quot;</p> - <p>This code will set your baud rate (speed), It will include the correct library file &quot;serial_hardware&quot;, and it will initialize the library with &quot;serial_hw_init()&quot;. You can change the speed if you wish, but you must change the speed in RealTerm as well.</p> + <p>So, now copy and past this into your code, I would put it somewhere after the line &quot;enable_digital_io&quot;, and somewhere before your main program which starts at &quot;forever loop&quot;.</p> + <p>This code will set your baudrate (speed), it will include the correct library file &quot;serial_hardware&quot;, and it will initialize the library with &quot;serial_hw_init()&quot;. You can change the speed if you wish, but you must change the speed in RealTerm as well.</p> <p>Now we can put some code that will send data to your PC. If you want to send the number 65 to your PC, you must use this code:</p>
       <codeblock>serial_hw_data = 65</codeblock>
<p>This code works because it is a procedure/function within serial_hardware.jal, and you have already included the serial_hardware library. serial_haredware.jal can be found in the &quot;lib&quot; folder of your jallib installation. You can open that file and read notes within it for more information and for other usable variables, functions and procedures.</p>
@@ -142,15 +142,15 @@
 end loop</codeblock>
<p>Compile and burn your code to your PIC, then turn on your circuit. You should get this while your led is blinking:</p> <image href="images/serial_communication_realterm_ab.jpg" width="400" otherprops="clickable"/> - <p>Awsome, now that you can send data to your pc. This was an important step since it will greatly help you with your troubleshooting by sending you readable information such as text, numbers and other types of data.</p> + <p>Awesome, now that you can send data to your pc! This was an important step since it will greatly help you with your troubleshooting by sending you readable information such as text, numbers and other types of data.</p> <p>If you feel your programming skills are not as good as they should be, practice practice practice! Continue using the language reference at <xref href="http://www.casadeyork.com/jalv2/jalv2/index.html"; format="html">http://www.casadeyork.com/jalv2/jalv2/index.html</xref></p>
     </section>
-    <section>
+    <section id="pc2pic">
       <title>Write code to send data from PC to PIC</title>
- <p>In the beginning, you may not have a use for sending data from your PC to your circuit, so you may skip this and go on to other things. </p> - <p>Here we are going to get the PIC to recieve data from the PC. We will write some code that will only start blinking a led when you send data to the PIC. Also we will tell the PIC to send the number 65 to the PC once per second.</p> + <p>In the beginning, you may not have a use for sending data from your PC to your circuit, so you may skip this and go onto other things. </p> + <p>Here we are going to get the PIC to receive data from the PC. We will write some code that will only start blinking a led when you send data to the PIC. Also we will tell the PIC to send the number 65 to the PC once per second.</p> <p>We will now learn to use the following variables from serial_hardware.jal:</p> - <p><b>serial_hw_data_available</b> - If the PIC recieved data, this variable will equal TRUE, otherwise FALSE</p> + <p><b>serial_hw_data_available</b> - If the PIC received data, this variable will equal TRUE, otherwise FALSE</p> <p><b>serial_hw_data</b> - If data is available, this variable will contain the data</p>
       <p>So let&apos;s modify your current loop:</p>
       <codeblock>forever loop
@@ -174,12 +174,12 @@
    if serial_hw_data_available then -- check if there is data available
    end if
 end loop</codeblock>
- <p>You will need to create a variable &quot;x&quot; before your &quot;forever loop&quot;, this variable will hold the data when you want to recieve it:</p> + <p>You will need to create a variable &quot;x&quot; before your &quot;forever loop&quot;, this variable will hold the data when you want to receive it:</p>
       <codeblock>var byte x</codeblock>
<p>Now you have a place to store the data, so you may now write a line within your &quot;if&quot; statement to get the data:</p>
       <codeblock>x = serial_hw_data</codeblock>
<p>Then build a for loop after that to blink the led &quot;x&quot; number of times</p> - <codeblock>for x loop -- loop (x number of times) using data recieved on serial port + <codeblock>for x loop -- loop (x number of times) using data received on serial port
    led = on
    _usec_delay(250000)
    led = off
@@ -227,19 +227,19 @@
       <p>As you can see, this code will do the following:</p>
       <p>1. delay 1 second</p>
       <p>2. send the number 65 via serial port</p>
- <p>3. see if there is data waiting for us, if so, get it and blink the led (the number of times of the data recieved)</p> + <p>3. see if there is data waiting for us, if so, get it and blink the led (the number of times of the data received)</p>
       <p>4. loop back to the start</p>
- <p>So, turn it on, you will start getting decimal numbers: &quot;65 65 65 65 65&quot; or ascii: &quot;AAAAAA&quot; in RealTerm. Now send your PIC the number 5, you will see your led blink 5 times. Now isn&apos;t that awsome!</p> + <p>So, turn it on, you will start getting decimal numbers: &quot;65 65 65 65 65&quot; or ascii: &quot;AAAAAA&quot; in RealTerm. Now send your PIC the number 5, you will see your led blink 5 times. Now isn&apos;t that awesome!</p>
     </section>
     <section>
       <title>PIC to PIC ommunication via serial port</title>
<p>Sending data to your PC is not the only use. If you have an extra PIC laying around, we can get two PIC&apos;s to talk to each other. And it&apos;s quite easy too!</p> - <p>I think you can do this on your own by now, You know how to make one PIC send data, and how to make a PIC recieve data, so all you have to do is write some sending code on one PIC and recieving code on the other.</p> + <p>I think you can do this on your own by now, you know how to make one PIC send data, and how to make a PIC receive data, so all you have to do is write some sending code on one PIC and receiving code on the other.</p> <p>Build another circuit the same as your current one, then do the following:</p>
       <p>1. connect the TX pin from PIC # 1 to the RX pin of PIC # 2</p>
       <p>2. connect the RX pin from PIC # 1 to the TX pin of PIC # 2</p>
- <p>On one of your PIC&apos;s, make it send data every one second, like we did before at &quot;Write code to send data from PIC to PC&quot;</p> - <p>On the other PIC, make it loop continuously. Put an if statement in the loop that will see if there is data available, and if there is, make the led blink once, like we did at &quot;Write code to send data from PC to PIC&quot;</p> + <p>On one of your PIC&apos;s, make it send data every one second, like we did before at <xref href="#serial_comms/pic2pc">Write code to send data from PIC to PC</xref>.</p> + <p>On the other PIC, make it loop continuously. Put an if statement in the loop that will see if there is data available, and if there is, make the led blink once, like we did at <xref href="#serial_comms/pc2pic">Write code to send data from PC to PIC</xref>.</p>
       <p>You should then see your led blinking on your second PIC.</p>
       <p>Wow, that was a lot, now I think you know your stuff!</p>
     </section>
-- 
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jallib?hl=en.


Reply via email to