breadboard and hserout interference?


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Jul 2006
    Posts
    76

    Default breadboard and hserout interference?

    I have two PIC16F628A's and I am trying to get them to communicate serially with each other. When a button is pressed, the LED on the receiving PIC should go on (similarily, when it is released the LED with go off). Unfortunately this is not working. I am wondering if the breadboard is somehow interfering with the packets...my code is below.

    Any help is appreciated!

    -Mike

    transmitter
    ---------------------

    ' Set transmit register to transmitter enabled
    DEFINE HSER_TXSTA 20h

    ' Set baud rate
    DEFINE HSER_BAUD 2400

    cmcon = 7

    Main:

    If (PORTA.1 = 0) then
    hserout ["1"]
    endif
    if (PORTA.1 = 1) then
    hserout ["2"]
    endif
    goto main
    end

    -----------------------
    Receiver
    ------------------------

    define HSER_CLROERR 1
    define HSER_RCSTA 90h
    define HSER_BAUD 2400

    Msg Var BYte
    cmcon = 7

    Main:
    hserin [Msg]
    if (Msg == "1") then
    high PORTA.1
    endif
    IF (Msg == "2") then
    low PORTA.1
    endif
    goto main

  2. #2
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    Try removing one of the "=" from each "IF" in your receiver program.
    Keith

    www.diyha.co.uk
    www.kat5.tv

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


    Did you find this post helpful? Yes | No

    Default

    my bet is more about possibility of a buffer overflow.
    Try this one for the transmitter
    Code:
    Set transmit register to transmitter enabled
    DEFINE HSER_TXSTA 20h
    
    ' Set baud rate
    DEFINE HSER_BAUD 2400
    
    cmcon = 7
    
    Main:
    
        If (PORTA.1 = 0) then
            hserout ["1"]
            while PORTA.1=0 : Wend : pause 500
            endif
        if (PORTA.1 = 1) then
            hserout ["2"]
            while PORTA.1=1 : wend : pause 500        
            endif
    
    goto main
    end
    what about your crystal speed? Config fuses? Schematic?
    Steve

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

  4. #4
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    To answer your question directly, I have done a lot of serial projects on breadboards and never had an issue.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e
    my bet is more about possibility of a buffer overflow.
    Try this one for the transmitter
    Code:
    Set transmit register to transmitter enabled
    DEFINE HSER_TXSTA 20h
    
    ' Set baud rate
    DEFINE HSER_BAUD 2400
    
    cmcon = 7
    
    Main:
    
        If (PORTA.1 = 0) then
            hserout ["1"]
            while PORTA.1=0 : Wend : pause 500
            endif
        if (PORTA.1 = 1) then
            hserout ["2"]
            while PORTA.1=1 : wend : pause 500        
            endif
    
    goto main
    end
    what about your crystal speed? Config fuses? Schematic?
    It sounds like you only want to send a character on the state change of the switch. Use a bit variable such as current_state for the last known state.
    This way, you won't hang the program up waiting for the switch to change.

    Read_switch:
    if (PORTA.1= current_state) then goto main ; No change goto main program
    hserout [PORTA.1 + $30] ; Make the switch value the ASCII equivelent and send it.
    current_state = PORTA.1 ; Current_state = switch value
    goto main ; How neat is that?!?

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


    Did you find this post helpful? Yes | No

    Talking

    for sure i need to sleep!
    Steve

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

  7. #7
    Join Date
    Jul 2006
    Posts
    76


    Did you find this post helpful? Yes | No

    Default

    Thanks for the tips guys. I try it out and get back to you on the results...

    -Mike

  8. #8
    Join Date
    Jul 2006
    Posts
    76


    Did you find this post helpful? Yes | No

    Default Synchronizing PIC's

    Thanks for the responses. I tested the program and it turns out that you were right. It must have been a buffer overflow. One last thing, though. Eventually I will connect Rx and Tx modules to my PIC's. To synchronize these I am trying to send synchronizing variables to balance the modules. My code must be incorrect, though, because it is not working. Here is the code for the transmitter:

    Pre CON $A5
    Synch CON "~"
    HSEROUT [Pre,Synch,"1"]

    and the receiver code,

    Synch CON "~"
    HSERIN [WAIT(Synch),Msg]

    Thanks for the help!

    -Mike

  9. #9
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    Try this instead:

    HSERIN [WAIT("~"),Msg]

  10. #10
    Join Date
    Jul 2006
    Posts
    76


    Did you find this post helpful? Yes | No

    Default

    Thank you very much everyone for the help and patience. I finally got it working. mister_e mentioned a buffer overflow. Is that on the transmitter, receiver or both? Thanks again everyone...

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