Should I use serin2 or HSERIN?


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2006
    Posts
    92

    Default Should I use serin2 or HSERIN?

    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
    Last edited by TonyA; - 20th April 2007 at 01:10.

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    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 Linquist

  3. #3
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Correction - you MUST use SERIN or SERIN2 if you don't have a Max232 or some other inverter between the PIC and the PC.
    Charles Linquist

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    AND/OR you don't need interrupt and few rings and bell the USART may provide.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Apr 2006
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    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

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by TonyA View Post
    inv9600 con 16468 ' <-----by the way what's happening here?
    The little green book can explain this.

Similar Threads

  1. GPS $GPRMC to PIC16F684. Need help with SERIN2
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th November 2009, 09:47
  2. Getting SERIN2 to work?
    By BobPigford in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 22nd July 2009, 20:10
  3. HSERIN vs Serin2
    By Rob in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 13th February 2008, 16:50
  4. SERIN2 digit parsing
    By skimask in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 7th January 2007, 23:15
  5. Hserin not working...
    By robert0 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 22nd August 2005, 12:25

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts