PDA

View Full Version : Should I use serin2 or HSERIN?



TonyA
- 20th April 2007, 00:22
Hi,

I've written a small program in Python that sends serial data out of my PC.

Now I'm wondering which would be better to use, SERIN2 or HSERIN?

I am just going to be sending bytes out, one at a time. Not a lot of data at first. Just to do things initially like turn on a LED connected to my pic.

(My Pyhton program can send data as a string, so I'm wondering what to send out that can be read by the PIC)

Thanks for any advice.

Tony

Charles Linquis
- 20th April 2007, 01:23
If you have a chip such as a MAX232 to do inversion/translation, then HSERIN is by far the best choice, since it has buffer. You don't have to sit around waiting for characters to come in.

You MUST use HSERIN if you don't have an inverter between your PC and the PIC.

Charles Linquis
- 20th April 2007, 02:52
Correction - you MUST use SERIN or SERIN2 if you don't have a Max232 or some other inverter between the PIC and the PC.

mister_e
- 20th April 2007, 14:47
AND/OR you don't need interrupt and few rings and bell the USART may provide.

TonyA
- 20th April 2007, 15:47
Hi,

Ok, I see. Thanks for the info. I thought I would try SERIN2/SEROUT2 at first since there is a simple example of it here:


Taken from the Physical Computing website (Dan O'Sullivan, Tom Igoe)

"The example below shows serin2 in action, and uses a timeout and a label to jump to on timeout. In it, <B>we're waiting for a byte value in (0 - 255),</B> and storing it in a variable called inputData. If we get data, we set pulseWidthVar equal to the new value. If we get no data, we skip to nodata, and use the last value we had for pulseWidthVar:"

inv9600 con 16468 ' <-----by the way what's happening here?

inputData var byte ' variable to receive data into
pulseWidthVar var byte

' set initial value for pulseWidthVar
pulseWidthVar = 255

main:
serin2 portc.7, 16468, 10, nodata, [inputData]
pulseWidthVar = inputData

nodata:
pulsout portb.2, pulseWidthVar
goto main


Their example above is for driving a servo motor, but I'll be just lighting a LED at first.

They said; "As with serout2, we can receive data in a number of formats using serin2.<B> The simplest is to receive it raw. If we expect a single byte, put a byte variable in the data parameter."</B>

So would anything being received by the pic via serial output from my PC be automatically stored in the byte variable (inputData)?

My Python program sends serial data out as a string. I can send out any string. I'm a little confused here probably because I haven't read up on it:

Must the string that's being sent out of my PC be formatted in a special way, in order to be received by the above example, or will whatever is sent automatically be stored in the inputData variable?

It states in the example; "we're waiting for a byte value in (0 - 255)", so does this mean my Python program must send a string containing only numbers 0-255?

The Python code that does the sending looks like this:

ser.write("Hello World") #write a string to com port

(I've been using <a href="http://www.microsoft.com/technet/sysinternals/utilities/portmon.mspx">PortMon </a>to monitor my com port and <I>anything</I> I type in place of the "Hello World" string is being sent out, numbers, words.)

Thanks again,
Tony

skimask
- 20th April 2007, 16:05
inv9600 con 16468 ' <-----by the way what's happening here?

The little green book can explain this.