PDA

View Full Version : SerIn and SerOut



Dwayne
- 21st July 2004, 16:54
Hello Folks,

One of the fun things to accomplish on a Chip, is Serial Communications. There are many ways to accomplish this, but the trick lies in the Success of making it work.

SerIn and SerOut are two Basic Functions that I see many folks use to communicate serially between two chips. Most of the time the code is correct (or close to it), and other problems arise that keeps the communication from happening. Here are a few tips to help make that transition a little easier.

1. Make sure your Pins that you are using are I/O pins.
2. Make sure your chip is running (MCLR not on Reset)
3. Make sure there is no noise between the two pins. You may need a Resistor to Ground for this.
4. Make sure you are using the simplest of the SerOut commands. No "Additives" yet!... Got to get the basics going first.
5. Use the same Baud Rates, and use a SLOW Baud rate.
6. Its best to use the same Clock speed at first, until communications has been established.


Now.. For SerOut.

SerOut PinNumber,T2400,DataOut

Suppposingly Serout changes the Pin you are using to a output pin for you... I prefer doing it myself with the TRIS registers at the top... Yeah.. its redundant...but it satisfies me.

1. Give DataOut a value like the number 1.
2. Put it in a loop.

Loop:
SerOut PinNumber,T2400,DataOut
Pause 100 'Delay for Receive scope
goto Loop

3. Now SCOPE it! If you cannot see a Start Bit, then your number one in Binary format on your scope, then find your problem. Its not worth going any further. Remember, you must narrow down your variables of error to debug something properly.


Now, you have a wonderful Scoped out "1" on your scope. Lets look at the receive end now.

There is a trick that I like to use... I like using two pins (at first) to verify my incoming data. If you do not have a LCD to "LCDout" your data, you can use your scope to check your data. If you have a Duel Trace scope, you can connect one lead to the transmitter pin, and the other lead to the Transmittter pin of the Reciever. That way you should be able to see that BOTH chips have the exact same wave....


SerIn PinNumber,T2400,DataRec


Remember that SerIn automatically switches this to a Input pin...But if you want, you can change the TRIS registers to support a I/O as Input.


First, lets put it in a loop ok?

DataRec Var byte


Loop:
SerIn PinNumber, T2400,DataRec
SerOut PinNumber2,T2400,DataRec
goto Loop

Or, if you have LED's...and want to use PortB..(Make sure all 8 bits of PortB are assigned to Outputs! TRISB=%00000000 !

Loop:
SerIn PinNumber,T2400,DataRec
PortB=DataRec
Goto Loop:



What this does, is Immediately output your DataRec to another pin on the receiver. If you scope that Output pin on that receiver, it should be exactly like the Output pin on your Transmitter Chip.

Or your LED's will have the Binary equiv. of your data being sent.

You have verified that the data being transmitted is correct, the data being Received is correct, and now can play with your Baudrate, extra features of Serin and Serout, or finish your project up.

Enjoy...

Dwayne