Serial comm between two PICs


Closed Thread
Results 1 to 25 of 25

Hybrid View

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

    Default

    Hi ALFRED,

    When the program gets to the SEROUT statement, the value of b0 is always 0.
    Code:
    Tx:
    
    Include "modedefs.bas"
    b0 VAR BYTE
    
    Start:
    IF PortB.1 = 1 THEN LET b0 = 1
    LET b0 = 0
    SEROUT PortB.0, N2400, [b0]
    GOTO Start
    >> Does the Rx wait for the data or if there isn't any go to the next line of code?
    Yes, the way you have it now, it will wait forever to receive a byte. If you wanted it to continue if it doesn't receive anything, you can add a timeout to the SERIN statement.

    >> Do the SERIN SEROUT commands have to be executed at the same time for the communication to be successful.
    YES!

    DT

  2. #2
    Join Date
    Feb 2006
    Posts
    20

    Question

    Hi, i just realized that I typed my code in wrong. I had it the way you suggested but it still doesn't work. any other ideas of what could be wrong?
    Thanks for any more help.

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

    Default

    Well, it wasn't really a suggestion. I was just pointing out part of the problem.

    My suggestion would be to place the b0 = 0 line just prior to the IF PortB.1 = 1 line. Like this...
    Code:
    Tx:
    
    Include "modedefs.bas"
    b0 VAR BYTE
    
    Start:
        LET b0 = 0
        IF PortB.1 = 1 THEN LET b0 = 1
        SEROUT PortB.0, N2400, [b0]
        PAUSE 10
    GOTO Start
    And, add a short pause in the loop. Just to space things out a bit.

    Then on the receiving end...
    Code:
    Rx:
    
    Include "modedefs.bas"
    b0 VAR BYTE
    
    Start:
        SERIN PortB.0, N2400, [B0]
        IF b0 = 1 THEN 
            HIGH PortB.1
        ELSE
            LOW PortB.1
        ENDIF
    GOTO Start
    DT

  4. #4
    Join Date
    Sep 2003
    Location
    Vermont
    Posts
    373

    Default

    Start:
    LET b0 = 0
    IF PortB.1 = 1 THEN LET b0 = 1
    SEROUT PortB.0, N2400, [b0]
    PAUSE 10
    GOTO Start

    Don't forget the "ENDIF"

    Start:
    LET b0 = 0
    IF PortB.1 = 1 THEN LET b0 = 1
    * ENDIF*
    SEROUT PortB.0, N2400, [b0]
    PAUSE 10
    GOTO Start

  5. #5
    Join Date
    Feb 2006
    Posts
    20

    Question

    Hi, I tried Ron Marcus's "endif" and it did not compile. nothing seems to be working and I am beginning to thing that I should try the HSERIN and HSEROUT commands instead. My actual application will be a PIC 18F4320 PIC controlling 12 servos and monitoring 12 pushbuttons. The idea is to take the load of controlling servo motion routines of the master controller. I want to control the motion routines of the servos with the master controller via serial link. Does anyone have any ideas? I think that the hardware serial port would make the timing requirements easier to deal with but I do not fully understand the HSERIN HSEROUT commands and USAURT could someone please explain all this to me?

  6. #6
    Join Date
    Sep 2003
    Location
    Vermont
    Posts
    373

    Default

    O.K... Try this,

    Start:
    b0 = 0
    IF PortB.1 = 1 THEN
    b0 = 1
    ENDIF
    SEROUT PortB.0, N2400, [b0]
    PAUSE 10
    GOTO Start

    Now, it looks like you are using Stamp type conventions for labels. b0 is not very descriptive.

    button1 var portc.0

    This will alias the above port pin (can be any pin) so you can use a more descriptive term and it will be easier to follow the program in the future. Also, "Let" is unnecessary with PBP. It will still work,and if it is habit, then do it. Do you have the apropriate pullup(down) resistors for your switches?

  7. #7
    Join Date
    Feb 2006
    Posts
    20

    Exclamation

    HI, I tried the code that Ron Marcus posted and it did not work. I think the problem is in the receiver PIC software, (when I hook a speaker up to the serial line I can hear the data flowing). I have now tried several ways to make a serial connection but none worked. These attempts included DEBUG and DEBUGIN commands as well as HSERIN and HSEROUT commands. I would be extremely happy if someone could post some sample code and hardware information on getting a serial connection working between two PICs using any method ( HSERIN, DEBUG ect.). I appreciate any help you can offer on this problem.

Similar Threads

  1. Pic to pic interrupt ans serial comm
    By ronjodu in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 10th May 2008, 23:43
  2. Multiple Pics to One serial port
    By Rleonard in forum Serial
    Replies: 1
    Last Post: - 18th January 2007, 19:30
  3. Big characters on HD44780 4x20
    By erpalma in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 7th January 2007, 03:21
  4. 16F877, DS18S20 and Serial Comm Problem
    By YellowTang in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 26th April 2004, 11:36
  5. serial comm from Pic to STAMP
    By d1camero in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th April 2004, 00:58

Members who have read this thread : 0

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