Serial comm Problems


Closed Thread
Results 1 to 5 of 5
  1. #1
    Fossil's Avatar
    Fossil Guest

    Default Serial comm Problems

    Hi, I am currently doing my final year project and have been having problems with the serout2 and serin2 commands. At first, I written a simple program which is when I pressed 1 button of chip A, the led on chip B will light up. It works but whenever I press it after resetting both chips, the the first press of the button will not work, it will only work on the second time.

    I solved the problem by sending a blank message before starting the program. But now I seem to be stuck with the same problem again when I did a more complicated again.

    DEFINE OSC 4
    ADCON1=7
    TRISA=%00111000
    TRISB=%00000001
    TRISC=%00011000
    PRESS VAR BYTE
    REC VAR BYTE
    PORTA=$00
    PORTB=$00
    PORTC=$00

    BEGIN: PRESS=5
    SERIN2 PORTC.4,3313,[WAIT("ABC"),REC]
    PAUSE 50
    SEROUT2 PORTC.5,3313,["ABC",PRESS]
    SEROUT2 PORTC.5,3313,["ABC",PRESS]
    HIGH PORTA.0
    PAUSE 250
    LOW PORTA.0

    READY: SERIN2 PORTC.4,3313,[WAIT("ABC"),REC]
    HIGH PORTA.0

    REPLY: IF PORTA.3=0 THEN
    PAUSE 300
    IF PORTA.3=0 THEN
    PRESS=1
    SEROUT2 PORTC.5,3313,["ABC",PRESS]
    HIGH PORTA.2
    PAUSE 100
    LOW PORTA.2
    LOW PORTA.0
    ELSE
    PRESS=2
    SEROUT2 PORTC.5,3313,["ABC",PRESS]
    HIGH PORTA.1
    PAUSE 100
    LOW PORTA.1
    LOW PORTA.0
    ENDIF
    ELSE
    GOTO REPLY
    ENDIF
    GOTO READY
    END

    DEFINE OSC 4
    ADCON1=7
    TRISA=%00000100
    TRISB=%00000001
    TRISC=%00011000
    PRESS VAR BYTE
    REC VAR BYTE
    PORTA=$00
    PORTB=$00
    PORTC=$00

    BEGIN: PRESS=5
    PAUSE 50
    SEROUT2 PORTC.5,3313,["ABC",PRESS]
    SEROUT2 PORTC.5,3313,["ABC",PRESS]
    SERIN2 PORTC.4,3313,[WAIT("ABC"),REC]
    HIGH PORTA.0
    PAUSE 250
    LOW PORTA.0

    READY: IF PORTA.2=0 THEN
    LOW PORTA.0
    LOW PORTA.1
    SEROUT2 PORTC.5,3313,["ABC",PRESS]
    HIGH PORTA.3
    PAUSE 150
    LOW PORTA.3
    ELSE
    GOTO READY
    ENDIF

    RECEIVE: SERIN2 PORTC.4,3313,[WAIT("ABC"),REC]
    SELECT CASE REC
    CASE 1
    HIGH PORTA.0
    CASE 2
    HIGH PORTA.1
    CASE ELSE
    GOTO RECEIVE
    END SELECT
    GOTO READY

    END

    Can anyone help me with this problem?

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


    Did you find this post helpful? Yes | No

    Default

    Hi Fossil,

    I think it's just a simple problem. Since your using (300 baud true), the output needs to idle high for a short time, about 7ms (2 bit periods) minimum before sending the first data. So, at the beginning of your program use.

    HIGH PORTC.5
    pause 10

    I think that should fix it.

    HTH,
      Darrel

  3. #3
    Fossil's Avatar
    Fossil Guest


    Did you find this post helpful? Yes | No

    Talking

    Ok thanks alot. It didn't really work but it triggered an idea.

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


    Did you find this post helpful? Yes | No

    Default

    Well, don't keep us in the dark. How did you fix it?

  5. #5
    Fossil's Avatar
    Fossil Guest


    Did you find this post helpful? Yes | No

    Default

    Originally posted by Darrel Taylor
    Well, don't keep us in the dark. How did you fix it?
    Opps. Didn't notice your last reply. Actually I just send out preamble bits before sending out the data I want to send. So before sending, I send out '01010101' first. And it works.

Similar Threads

  1. Serial comm between two PICs
    By ALFRED in forum Serial
    Replies: 24
    Last Post: - 13th March 2014, 23:22
  2. Big characters on HD44780 4x20
    By erpalma in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 7th January 2007, 02:21
  3. Serial Communication Problems (Strange!!)
    By Armando Herjim in forum Serial
    Replies: 1
    Last Post: - 20th June 2006, 22:46
  4. 16F877, DS18S20 and Serial Comm Problem
    By YellowTang in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 26th April 2004, 10:36
  5. serial comm from Pic to STAMP
    By d1camero in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th April 2004, 23:58

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