SERIN and SEROUT


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Sep 2009
    Location
    Brisbane, Australia
    Posts
    10

    Question SERIN and SEROUT

    Hi all,

    First post here, hopefully one of many (helping as well as getting help)

    I have a question that I'm sure has a very simple answer, but I'm having trouble with it. I've got a situation where I need to use multiple PICs in a project (I'm working with the PIC16F628A on a 4MHz XTAL) and I need them to be able to send data to one another. One will only send data and one will only receive data. Nothing fancy, it only needs to send a single digit number.

    What I'd like to know is, what is some basic code to put on PIC A and PIC B to get PIC A to send numbers 0 to 3 via SEROUT and have PIC B recognise those numbers and, say, light up an appropriate LED. Currently I'm using the following code:

    'PIC A (Sender)
    INCLUDE "modedefs.bas"

    x VAR byte

    main:
    FOR x = 0 to 3
    SEROUT PORTB.0, T2400, [x]
    PAUSE 1000
    NEXT
    GOTO main


    'PIC B (receiver)
    INCLUDE "modedefs.bas"

    x VAR byte

    main:
    SERIN PORTB.0, T2400, [x]
    IF x = 0 THEN HIGH PORTB.1
    IF x = 1 THEN HIGH PORTB.2
    IF x = 2 THEN HIGH PORTB.3
    IF x = 3 THEN HIGH PORTB.4
    GOTO main


    I'm aware it may also be a wiring issue... I just have a straight wire (I'm breadboarding this first) going from PORTB.0 on PIC A to PORTB.0 on PIC B.

    Anyone have some advice?

    Thanks in advance!

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hello CumQuaT,
    Welcome to the forum.
    Quote Originally Posted by CumQuaT View Post
    Anyone have some advice?
    You could start by telling us what kind of problem you are having . . . DOA . . . ?
    A couple of things, DEFINE OSC 4 near the top of your code.
    If you are not using analog on PortA add cmcon = 7 to disable the comparators there so it doesn't trip you later.
    Set up your Ports as high or low before setting your TRIS registers, and do not skip setting those.
    Code:
    'a config statement should go here unless default config is just right
        DEFINE OSC 4
        cmcon = 7
        PortA = 0
        PortB = 0 set all output latches low
        TrisA = %00000000 'set PortA as all outputs
        TrisB = %11100000 '5,6,7 as inputs all others as outputs
    Main:
        ' . . . . your code goes here
        goto Main
    end
    EDIT: Serial data, True idles high, and wants a pull up resistor on the data line to 5v +
    Inverted idles LOW and wants a resistor pulling to logic LOW or ground.
    Last edited by Archangel; - 1st September 2009 at 05:22.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Sep 2009
    Location
    Brisbane, Australia
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Reply

    Hi! Thanks for the warm welcome!

    I actually described precisely what my problem is. The code I have with the connections I have isn't transmitting or receiving single numbers. I am also not using porta at all in my code.

  4. #4
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    See page 131 of PBP manual. Since you have used bracket pic is waiting for QUALIFIER first. Remove brackets from SERIN.

    SERIN PORTB.0,T2400,x

    Follow Joe advice on the setting even if you don't use PortA.
    Last edited by aratti; - 1st September 2009 at 07:55.
    All progress began with an idea

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


    Did you find this post helpful? Yes | No

    Default

    All the above and
    I'm aware it may also be a wiring issue... I just have a straight wire (I'm breadboarding this first) going from PORTB.0 on PIC A to PORTB.0 on PIC B.
    You also have the "grounds" connected? Two wires are needed.
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Sep 2009
    Location
    Brisbane, Australia
    Posts
    10


    Did you find this post helpful? Yes | No

    Default reply

    You mean the grounds to the PIC? As in VSS? Or are there grounds required in regards to wiring the two pics together in serial?

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by CumQuaT View Post
    You mean the grounds to the PIC? As in VSS? Or are there grounds required in regards to wiring the two pics together in serial?
    Yep, VSS. The way you had it worded "a straight wire" made me think you may not have two.
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by CumQuaT View Post
    Hi! Thanks for the warm welcome!

    I actually described precisely what my problem is. The code I have with the connections I have isn't transmitting or receiving single numbers. I am also not using porta at all in my code.
    I must be getting senile . . . single numbers . . . or anything usable (DATA), if you send a string does that show up ? Or do you get nothing at all ? Do your Pics do anything? Do you have a heartbeat LED on them to ascertain they are actually working?
    As mentioned above serial is 2 wire signal and ground, coax or twisted works fine, (doorbell wire makes for cheap twisted pair).
    Question: Are you using a resonator / crystal / or INternal RC Oscillator ? Do the default config statements located in the 16F628A.inc file in the PBC root directory agree with what you are trying to use? Are you using PBC or PBP ?
    Last edited by Archangel; - 2nd September 2009 at 04:51.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  9. #9


    Did you find this post helpful? Yes | No

    Default Serin Command

    Has anyone see a change on the SERIN command with ver 2.60 upgrade?

    I had this command working fine with v2.50a and now it will not work on 2.6

    Any ideads? the ON9600 seems to be the issue.

    Code:
    Serin PORTC.5,ON9600,B0
    Thanks,
    Kevin

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by hatchethand1000 View Post
    Has anyone see a change on the SERIN command with ver 2.60 upgrade?

    I had this command working fine with v2.50a and now it will not work on 2.6

    Any ideads? the ON9600 seems to be the issue.

    Code:
    Serin PORTC.5,ON9600,B0
    Thanks,
    Kevin
    Is this new code or old code that worked with 2.5?
    Did you remember to include modefs.bas?
    Can you find the new thread button?
    Dave
    Always wear safety glasses while programming.

  11. #11
    Join Date
    Sep 2009
    Location
    Brisbane, Australia
    Posts
    10


    Did you find this post helpful? Yes | No

    Default reply

    Hi all,

    I resolved the issue. I just had to remove the brackets when using SERIN. Aratti was right.

    Thanks for the help!

Similar Threads

  1. PIC16f877 code crosses boundary @800h
    By inventosrl in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th April 2009, 22:03
  2. Advice-scrutiny for my serial controller
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th December 2008, 17:11
  3. Help with serin, serout, Manchester encoding
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 5th April 2007, 13:31
  4. Serial interface with RFID reader
    By brid0030 in forum Serial
    Replies: 8
    Last Post: - 23rd January 2007, 06:23
  5. SerIn and SerOut
    By Dwayne in forum FAQ - Frequently Asked Questions
    Replies: 0
    Last Post: - 21st July 2004, 15:54

Members who have read this thread : 5

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