Shop OBEX P1 Docs P2 Docs Learn Events
PIC16F84 to BS2 using SEROUT — Parallax Forums

PIC16F84 to BS2 using SEROUT

ArchiverArchiver Posts: 46,084
edited 2001-06-08 17:31 in General Discussion
I am trying to network a BS2 as a MASTER with PIC 16F84 SLAVES using
SEROUT/SERIN but am having trouble getting the chips to talk to each
other. I can't get the BS2 to receive anything. Any ideas would be
greatly appreciated.

The PIC generates a signal from a conditional event similar to the
code below (using PicBasic and MPLAB)-

loop:
if PIN0 = 1 Send_it 'If P0 is high goto the Send_it loop.
goto loop

Send_it:
SEROUT 2,N2400,("hello") 'Send "hello" 2400,N,8 on P2.
goto loop


The BS2 MASTER code I'm using looks like this-

hello var word
loop:
SERIN 2,16780,[noparse][[/noparse]hello] 'Receive data 2400,N,8 on P2.
debug hello,13
goto loop

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-06-08 17:31
    Hi Mark,

    Are you using PicBasicPro, or BasicMicro, or assembler?

    There are several things wrong with the BS2 master program.
    Hello is defined as a word variable, but your PIC is sending a
    string. The result is displayed as straight code values, not as
    decimal number. No handshaking is implemented on the BS2 master side,
    to match that on the PIC side. The result will be quite weird, maybe
    displaying a couple of random characters now and then.

    Try something like this, which receives the data as a 5 byte string
    and implements the handshaking...

    hello var byte(6) ' array to receive string
    hello(5)=0 ' puts a null terminator on the string.
    loop:
    SERIN 2\1,16780,[noparse][[/noparse]str hello\5] 'Receive 5 bytes 2400,N,8 on P2.
    ' when serin is ready, P1 goes high
    ' connect P1 to PIN0 on your PIC
    debug str hello,13
    goto loop

    or something like this, to receive one character at a time...

    x var byte
    loop:
    SERIN 2\1,16780,[noparse][[/noparse]x] 'Receive 1 byte 2400,N,8 on P2.
    ' when serin is ready, P1 goes high
    ' connect P1 to PIN0 on your PIC
    debug x
    goto loop

    In this last one, you have to send the CR from the slave.

    If you have an oscilloscope or even a voltmeter, that can be a great
    help to see if the signals are behaving as you expect. A tutorial on
    this can be found at:
    http://www.emesystems.com/BS2rs232.htm#SERINflow

    -- regards,
    Tracy Allen
    electronically monitored ecosystems
    mailto:tracy@e...
    http://www.emesystems.com


    >I am trying to network a BS2 as a MASTER with PIC 16F84 SLAVES using
    >SEROUT/SERIN but am having trouble getting the chips to talk to each
    >other. I can't get the BS2 to receive anything. I've read alot of
    >your information regarding Stamps on your web site and it seems like
    >you have expertise in this area.
    >
    >Any ideas would be greatly appreciated.
    > Mark Johnson
    >
    >The PIC generates a signal from a conditional event similar to the
    >code below (using PicBasic and MPLAB)-
    >
    >loop:
    >if PIN0 = 1 Send_it 'If P0 is high goto the Send_it loop.
    >goto loop
    >
    >Send_it:
    >SEROUT 2,N2400,("hello") 'Send "hello" 2400,N,8 on P2.
    >goto loop
    >
    >
    >The BS2 MASTER code I'm using looks like this-
    >
    >hello var word
    >loop:
    >SERIN 2,16780,[noparse][[/noparse]hello] 'Receive data 2400,N,8 on P2.
    >debug hello,13
    >goto loop
Sign In or Register to comment.