Shop OBEX P1 Docs P2 Docs Learn Events
Serin\Serout to BS2 — Parallax Forums

Serin\Serout to BS2

SteveDSteveD Posts: 64
edited 2005-11-05 21:54 in General Discussion
I am having trouble trying to figure out how to send a word sized variable to a BS2 from an SX28 using SX/B as a compiler.· The BS2 would be a master, an SX28 would be a slave.· I would like to·display this variable on the BS2's debug screen.· Thank you for any help you can give me.

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-01 16:32
    Remember that serial communication is byte-by-byte, so you would simply send it as two bytes. Just make sure that your receiver understands the order that you're sending the value so that it can be correctly reconstructed on that end.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • SteveDSteveD Posts: 64
    edited 2005-11-01 16:46
    I understand and have sent word sized serial data between 2 BS2's. Unsuccesfully I was trying to adapt the DS1620 project example code for the SX to send to a BS2.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-01 16:52
    Are you matching the baudmode? I'd suggest going with Open-True, as this leaves the serial line an an input state when done. In True mode, make sure you add a pull-up to the connection.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • SteveDSteveD Posts: 64
    edited 2005-11-01 17:33
    I have the BS2 set @ 396 I believe this is true 2400 baud no parity. I have the SX set @ " Baud CON T2400". I believe this is true 2400 no parity. As for the pull-up to the connection I am using MAX1483 (RS-485) driver and have succesfully used between 2 stamps with out pull-ups. If it were not too much trouble and in your spare time could you send a very simple code wich allows a variable sent be an SX28 to be recieved by a BS2 at 2400 True baud no parity?
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-01 18:16
    The SX/B help file is filled with SEROUT subroutines that I use every day (I manage the help file, so most of the code is mine)·-- all you have to do is set the baud rate and mode to what you need and make two calls, something like this:

    · TX_BYTE tempLo
    · TX_BYTE tempHi

    Where tempLo and tempHi are are the two bytes that build your 16-bit value.

    [noparse][[/noparse]Edit] I don't have any spare time, so I can't write and test a custom program for you.· That said, I was working with serial stuff the other day and I've stripped everything out of my program except the core of what you need.· Start with this.· Make sure your SERIN on the BASIC Stamp is set to receive low-byte, then high-byte.· On the BASIC Stamp end you should be able to DEBUG in HEX4 mode and see $1234 coming from the SX every second.

    And, don't use "magic numbers" in your PBASIC programs for the baudmode values -- this is the quickest way to an error.· I've posted my PBASIC program at least a dozen times ... I guess one more won't hurt.· I has all the baud rate and mode values built-in and saves a lot of errors if one will just use it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax

    Post Edited (Jon Williams (Parallax)) : 11/1/2005 6:30:53 PM GMT
  • SteveDSteveD Posts: 64
    edited 2005-11-04 16:27
    The SX and stamp are communicating but instead of the constant 200 the Stamp displays 232.
    Would someone point out to me what I am doing wrong here?

    DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
    FREQ 4_000_000

    temp con 200
    ' =========================================================================
    PROGRAM Start
    ' =========================================================================
    Start:
    PLP_A = %0001
    PLP_B = %00000000
    PLP_C = %00000000
    Main:
    pause 3000
    SEROUT RA.0, T2400, temp
    GOTO Main

    ****************************************************************************

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    '
    [noparse][[/noparse] I/O Definitions ]
    DataIO PIN 7


    '
    [noparse][[/noparse] Constants ]
    T2400 CON 396

    '
    [noparse][[/noparse] Variables ]
    Reply VAR Byte 'Holds information sent from slave(s)
    '
    [noparse][[/noparse] Initialization ]
    Setup:
    DEBUG CLS
    '
    [noparse][[/noparse] Program Code ]
    MAIN:
    SERIN DataIO, T2400, [noparse][[/noparse]Reply]
    DEBUG DEC REPLY: PAUSE 1000
    DEBUG CLS
    GOTO MAIN
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-04 16:35
    I think the problem is you're attempting to use PBASIC style in SX/B where it doesn't work. Change your SX pin setup like this:

    PLP_A = %1110

    ... to enable the pullup or RA.0 -- yes, this is the opposite of PBASIC and something you have to keep in mind when going back an forth between the two languages.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-04 16:42
    I ran your programs with the change I suggested an it works.· Let me also suggest that you remove the PAUSE from the BS2 program since you have one in the SX/B program.· If the SX/B transmits in the middle of your BS2 PAUSE you will miss it or get a garbled value.· Change Main to this:

    Main:
    · SERIN DataIO, T2400, [noparse][[/noparse]reply]
    · DEBUG DEC reply, CR
    · GOTO Main

    That way you can see the value come in and be received properly.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • SteveDSteveD Posts: 64
    edited 2005-11-04 16:55
    I have the DataIO (stamp pin) and RA.0 connected together on PDB. I have made all changes you suggested mine still says 232.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-04 17:08
    Try my code -- this is running as you want it to run and I've copied and pasted right out of my editors:

    DEVICE··· SX28, OSCXT2, TURBO, STACKX, OPTIONX
    FREQ······4_000_000


    TestVal·· CON·· 200

    PROGRAM Start

    Start:
    · PLP_A = %1110
    Main:
    · PAUSE 1000
    · SEROUT RA.0, T2400, TestVal
    · GOTO Main



    Here's the BS2 compliment to it:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}


    DataIO· PIN···· 15
    ·
    T2400·· CON···· 396
    ·
    reply·· VAR···· Byte
    ·
    Setup:
    · DEBUG CLS

    ·
    Main:
    · SERIN DataIO, T2400, [noparse][[/noparse]reply]
    · DEBUG DEC reply, CR
    · GOTO Main


    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • SteveDSteveD Posts: 64
    edited 2005-11-04 17:47
    I copied and pasted your code I am getting random numbers from 0 to 255 and then only when I move my hand close to the SX chip. I noticed the debug screen says 9600 so I changed it to 2400 then just a screen full of asterisks. Any ideas?
  • BeanBean Posts: 8,129
    edited 2005-11-04 18:04
    The debug screen should be 9600.
    Do you have a common ground connection·between the BS2 and the SX ?
    What are you using to clock the SX chip ? Is it 4Mhz ?
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012
    Product web site: www.sxvm.com
    Available now... SX-Video OSD module $59.95 www.sxvm.com

    Those that would give up freedom for security will have neither.


    Post Edited (Bean (Hitt Consulting)) : 11/4/2005 6:07:55 PM GMT
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-04 19:15
    Steve,

    I'm setup on a PDB and am using one wire: between RA.0 on the SX and pin 15 on my BASIC Stamp. I have no idea what's going on at your end, but I can assure you that the code I posted does in fact work. Maybe you got a bad pin on either side. You could try a different pin -- just remember that you need to use 0 in the PLP register to pull-up the SX I/O pin.

    DEBUG output has nothing to do with the baud rate between the SX and the BASIC Stamp -- and in all BS2 modules except the BS2px, DEBUG is at 9600 baud.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • SteveDSteveD Posts: 64
    edited 2005-11-05 00:57
    Bean
    Yes to the common ground. 4MHZ internal clock. Thanks for answering the "Debug at 9600" I never paid attention to it before. I have tried external pull-up and pull-down resitors with the same response. The last time time I ran the program the debug RX indicator reacted only when I moved my hand close the PDB and I could tell that there was definitely not a 1 second pause between receiving. I know that the problem is not with the Stamp, I have a BOE, I hooked it to the PDB SX, same thing.

    Jon
    I too switched pins on the stamp to reflect your code and even tried different pins on the SX and same response. I feel much better knowing that I have at least a primitive understanding of sending the code between the two. Thanks for your time.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-05 01:04
    You CANNOT use the internal clock, it is not stable enough for serial communications. Notice that my code says OSCXT2, not OSC4MHZ.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • SteveDSteveD Posts: 64
    edited 2005-11-05 21:19
    I am hesitant in admiting that I noticed the directive OSCXT2. I was unsure of how to use the resonator. All the playing around I have done up to this point required nothing more than the internal clock. I just got so excited with the progress I was making (little steps I know) with the SX that I just stuck to what I was not intimidated by, I never looked into using the resonator.

    I know I wasted some of your time but I appreciate you giving me a better understanding of serial communication and showing me how to use the resonator.

    It works now and I even have the Stamp displaying a word sized variable from information sent from the SX!

    Steve
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-05 21:54
    That's great that you understand why it wasn't working and are now on your way. Now you can create all kinds of cool "Stamp helper" modules with the SX. Right now I'm working on two: a PSX helper (yes, it lets you activate force feedback in the controller), and a GPS helper. Both will connect to the BASIC Stamp using one wire and the bi-directional (open true) AppMod protocol.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.