Shop OBEX P1 Docs P2 Docs Learn Events
Communication Propeller - Basic Stamp — Parallax Forums

Communication Propeller - Basic Stamp

danielreisdanielreis Posts: 16
edited 2010-11-23 06:58 in Propeller 1
Hi guys,

I need to communicate Propeller with Basic Stamp 2pe.
I was thinking about using 2 wires, one for data in and one for data out, but it didn't work. I also tried to put a 22k resistor in the pin of the BS2pe that I was using for receive data from the propeller, but it also didn't work.

I searched about it here in the forum, but I didn't find anything. I only found some threads about communication between 2 props or 2 BS.

Can anybody help me with it?

Thanks in advance!

Daniel Reis

Comments

  • CampeckCampeck Posts: 111
    edited 2010-10-29 12:11
    well for one the BSpe is a 5v system and the prop is a 3.3v system. did you use resistors in series with the comm lines?
  • JonnyMacJonnyMac Posts: 9,235
    edited 2010-10-29 14:16
    You can use half-duplex (since the Stamp can't TX and RX at the same time), open-true comms between the chips, with the serial line being pulled up to 3.3v on the Propeller side. Make sure that the boards have common ground. I've done this, it works fine because the TTL threshold on the Stamp is 1.5v so 3.3v is a solid "1". Each side will create a "0" bit by pulling the line to ground. "Open" comms only ever drives the line one way so you don't require a series resistor.
  • CampeckCampeck Posts: 111
    edited 2010-10-29 18:44
    oooh. Fancy! disregard my ignorance on communication between ucontrollers.
  • danielreisdanielreis Posts: 16
    edited 2010-11-04 11:29
    Sorry about my delay to answer if it worked, but it's because this week was holiday here in Brazil, and I was travelling.

    I tried to connect both without resistors, and in a common ground as you said, Jonny, but it didn't work.
    I used the BS2_Functions OBJ from OBEX, and tried to use the following line, to make a test:

    BS.serout_dec(tx, number, baudRate, polarity, bits)

    I used 9600 baudRate, polarity inverted (0), 8 bits

    In Basic Stamp, I used:

    SERIN rx, baud, timeout, fail, [DEC rec]

    baud = 16468, that is 9600, 8-bit, no parity, inverted

    And when I try to run this, Basic Stamp can't receive anything from propeller.

    Is there anything wrong with my code?
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2010-11-04 17:28
    You did "Start" the BS2 object, correct?

    It should work ok.
    -Martin
  • $WMc%$WMc% Posts: 1,884
    edited 2010-11-04 17:53
    danielreis wrote: »
    Sorry about my delay to answer if it worked, but it's because this week was holiday here in Brazil, and I was travelling.

    I tried to connect both without resistors, and in a common ground as you said, Jonny, but it didn't work.
    I used the BS2_Functions OBJ from OBEX, and tried to use the following line, to make a test:

    BS.serout_dec(tx, number, baudRate, polarity, bits)

    I used 9600 baudRate, polarity inverted (0), 8 bits

    In Basic Stamp, I used:

    SERIN rx, baud, timeout, fail, [DEC rec]

    baud = 16468, that is 9600, 8-bit, no parity, inverted

    And when I try to run this, Basic Stamp can't receive anything from propeller.

    Is there anything wrong with my code?
    '
    If you would post both codes used, It would make this a lot easier.
    '
    Its hard to tell witch is at fault if any, being one sided.
    '
    What is the BS2's full code?
    '
    This is very easy to do, You just need both Micro's on the same page!
  • danielreisdanielreis Posts: 16
    edited 2010-11-05 05:36
    I tried it again, and it worked fine.
    I tested both sending data from propeller to basic stamp and from BS to propeller, and everything worked fine.

    Thanks everyone for the help!

    I just didn't understand why the communication from propeller to BS uses polarity inverted and from BS to propeller uses it non-inverted. What's the reason?
  • HumanoidoHumanoido Posts: 5,770
    edited 2010-11-05 06:30
    danielreis wrote: »
    I tried it again, and it worked fine.
    I tested both sending data from propeller to basic stamp and from BS to propeller, and everything worked fine. Thanks everyone for the help! I just didn't understand why the communication from propeller to BS uses polarity inverted and from BS to propeller uses it non-inverted. What's the reason?
    That sounds strange. Can you post the code and a drawing of your setup?
  • danielreisdanielreis Posts: 16
    edited 2010-11-05 07:31
    First, from propeller to Basic Stamp:
    Propeller:
    CON
    
      'ClkFreq: 80 Mhz
    
      _XINFREQ = 5_000_000          'Adjust the frequency          
      _CLKMODE = XTAL1 + PLL16X     'Adjust the frequency
    
      rx = 0
      tx = 1
      baudRate = 9600
      polarity = 0
      bits = 8
    
    OBJ
    
      bs :  "BS2_Functions"         'Basic Stamp 2 library
    
    VAR
    
      byte number  
    
    PUB start
    
      BS.start(31, 30)
    
      number := 0
    
      repeat
        BS.serout_dec(tx, number, baudRate, polarity, bits)    'send data to BS
        number++
        waitcnt(clkfreq + cnt)     '1 sec pause
    

    BS:
    ' {$STAMP BS2pe}
    ' {$PBASIC 2.5}
    
    
    tx  CON 0
    rx  CON 1
    
    baud   CON $4054
    timeout CON 3000
    
    number  VAR Byte
    
    start:
        SERIN rx, baud, timeout, fail, [DEC number]          'receive from propeller
        DEBUG CR, "Test ok, received: ", DEC number       'show data received on screen
        GOTO start           'loop
    
    fail:
        DEBUG CR, "Test failed, nothing received", cr
        GOTO start           'loop
    

    Now, from BS to propeller:

    Propeller:
    CON
    
      'ClkFreq: 80 Mhz
    
      _XINFREQ = 5_000_000          'Adjust the frequency          
      _CLKMODE = XTAL1 + PLL16X     'Adjust the frequency
    
      rx = 0
      tx = 1
      baudRate = 9600
      polarity = 1
      bits = 8
    
    OBJ
    
      bs :  "BS2_Functions"         'Basic Stamp 2 library
    
    VAR
    
      byte number  
    
    PUB start
    
      BS.start(31, 30)
    
      repeat
        number := BS.serin_char(rx, baudRate, polarity, bits)    'receive from BS; Tried to use "BS.serin_dec", but didn't work
        BS.serout_char(30, number, baudRate, 1, 8)       'show data received on screen
        waitcnt(clkfreq/2 + cnt)          '0.5 sec pause
    

    BS:
    ' {$STAMP BS2pe}
    ' {$PBASIC 2.5}
    
    
    tx  CON 0
    rx  CON 1
    
    baud   CON $54
    
    number  VAR Byte
    
    number = 0
    
    start:
        SEROUT tx, baud, [DEC number]         'send data to propeller
        PAUSE 1000                     '1 sec pause
        number = number + 1
        GOTO start                    'loop
    


    I connected TX pin of propeller(0) in RX of BS(0) and RX of propeller(1) in TX of BS(1), without resistors or anything else. I'm also using the same ground for BS and propeller
  • B_BertoniB_Bertoni Posts: 1
    edited 2010-11-08 04:05
    I'm with the same problem!
  • HumanoidoHumanoido Posts: 5,770
    edited 2010-11-23 06:58
    I have the system duplicated and working, however, the received result is truncated to one decimal place. Any idea how to format it to 3 integer places?
    number := BS.serin_char(rx, baudRate, polarity, bits) 'receive from BS; Tried to use "BS.serin_dec", but didn't work
    BS.serout_char(30, number, baudRate, 1, 8) 'show data received on screen
    
    attachment.php?attachmentid=75667&stc=1&d=1290524011
    367 x 259 - 18K
Sign In or Register to comment.