Serin Serout Help


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    Join Date
    Nov 2010
    Posts
    7

    Lightbulb Serin Serout Help

    Currently I am working on a project that involes serial communication between one PIC and another. The task is to flash an led at a rate (77) sent via serial. the code is as follows.

    Sender: PIC 16F877A

    CLEAR
    DEFINE OCS 4
    TRISA = %000000000


    LOOP1:
    SEROUT PORTA.0, 3, [77]
    GOTO LOOP1:
    END

    Receiver: PIC 12F683

    CLEAR
    ANSEL = 0
    CMCON0 = 7
    X VAR BYTE
    HIGH GPIO.2
    INPUT GPIO.1

    LOOP1:
    SERIN GPIO.1, 3, X
    GPIO.3 = 1
    PAUSE x
    GPIO.3 = 0
    GOTO LOOP1
    END

    any help would be appreciated thanks a lot

  2. #2
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    my guess is the LED is always on or you just see a blip once. try moving the serin outside of the loop. The way you have it it will be waiting for a serin every time through the loop. next problem is you are turning the led on, waiting "x" time, then turning it off. THEN you go right back to the top of the loop and turn it right back on.so if it doesn't hang on the serin, it turns on almost instantly. try adding a pause after you trun it off also. That is assuming GPIO.3 is your LED.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    On a 12F683, GPIO.3 is "Input Only" when not used as MCLR.
    You'll need to use a different pin for the LED.

    And the receiver has no way to know where each byte of serial data starts.
    The sender is continually sending data and the receiver looks for data whenever it looks for it.

    If the receiver starts looking in the middle of a byte, it doesn't know it's not the beginning of the transmission and will receive an invalid value.

    There needs to be some sort of handshaking, so the sender knows when the receiver will be ready to receive something before sending it.
    That will take another line between the two chips.
    Or, tri-state signaling on the single line (no sample code available).

    My recommendation ... add another line between the two chips, use SEROUT2/IN2 with FlowPin control.
    You can use GPIO.3 for the serial input (put FlowPin on another pin).
    DT

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Do not forget
    INCLUDE "modedefs.bas"

    And if you do not have enough pins for the flow control.
    From the manual. We sometimes refer to this as "waiting" for a character to know where we are.
    The list of data items to be received may be preceded by one or more qualifiers enclosed within brackets. SERIN must receive these bytes in exact order before receiving the data items. If any byte received does not match the next byte in the qualifier sequence, the qualification process starts over (i.e. the next received byte is compared to the first item in the qualifier list). A Qualifier can be a constant, variable or a string constant. Each character of a string is treated as an individual qualifier.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Nov 2010
    Posts
    7


    Did you find this post helpful? Yes | No

    Lightbulb Update

    thanks for the post unfortunately i have made little progress. I have set the flowpin using Serin2 and serout2 and i am using proper pins. my baud rate may have some issues I'm trying to use the slowest one for now. Currently the circuit does nothing, no flashing or anything, but i have verified with an oscilloscope that data is being sent. Hear is the new code.

    send:
    CLEAR
    DEFINE OCS
    TRISA = %000000000

    LOOP1:
    SEROUT2 PORTA.0\PORTA.1, 3313, [DEC 77]
    GOTO LOOP1:
    END

    recive:
    CLEAR
    ANSEL = 0
    CMCON0 = 7
    X VAR BYTE

    LOOP1:
    SERIN2 GPIO.1\GPIO.3, 3313, [DEC X]
    pause x
    GPIO.0 = 1
    PAUSE x
    GPIO.0 = 0
    PAUSE X
    GOTO LOOP1
    END

    thanks again any help would be appreciated.

  6. #6
    Join Date
    Nov 2010
    Posts
    7


    Did you find this post helpful? Yes | No

    Lightbulb Update

    Should I be using pull up resistors (22k, 4.7K, 2.2k)?

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    You will need to turn the analog off.
    The two links below should help. For now, after you read the one from Melanie, use the one from Darrel.
    http://www.picbasic.co.uk/forum/showthread.php?t=561
    http://www.picbasic.co.uk/forum/cont...54-All-Digital

    And if you could post all of your code and how the configs are set might also be helpful.
    Dave
    Always wear safety glasses while programming.

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