Shop OBEX P1 Docs P2 Docs Learn Events
SX to SX Serial — Parallax Forums

SX to SX Serial

ajajackajajack Posts: 26
edited 2008-08-14 15:40 in General Discussion
I am new to coding in SX. I would like to connect two SX chips via serial connection (4800). Now, I want to make it so that one acts as a transmitter and can control an led on the reciever end. In the end I would replace the serial wire with the RF Link that SparkFun sells. The RF link acts as a serial connection between the two however adds noise on the reciever end, sending bytes that the transmitter didn't send. So I need to make sure that the serout is synced with teh serin. I think there is a way to do that by checking for a certain header or something. I don't know much about this and I was wondering if anybody was able to help me with some coding. Thanks.

Post Edited (ajajack) : 7/22/2008 12:15:46 PM GMT

Comments

  • JonnyMacJonnyMac Posts: 9,215
    edited 2008-07-22 05:19
    On the slave side it's easy to look for a given byte sequence before moving on -- let's say you wanted to use "!SX" as your header; you could do something as simple as this:

    Main:
      char = RX_BYTE
      IF char <> "!" THEN Main
      char = RX_BYTE
      IF char <> "S" THEN Main
      char = RX_BYTE
      IF char <> "X" THEN Main
    
      ' header is valid
    


    In this example RX_BYTE is a shell for SERIN so that it only gets compiled once.
  • ajajackajajack Posts: 26
    edited 2008-07-22 12:12
    Thank you but I am still a bit stuck. I have worked up some code from what you said and also have been doing a lot of research so I attached my two files. I am using a BASIC Stamp as my transmitter at the moment because I have a bit more understanding of it I will change that later to SX. Anyways, I have the two chips programmed with the code I have attached and it still does not work. If anybody could help me that would be great.
  • JonnyMacJonnyMac Posts: 9,215
    edited 2008-07-22 17:06
    This first problem you have is that you're trying to use the internal oscillator -- this won't work with SERIN (not accurate enough); you must use an external osc source (resonator, etc.).

    I've attached a test program for you to work with; if you have a PDB you can test both sides.
  • John CoutureJohn Couture Posts: 370
    edited 2008-07-22 21:29
    Hey Jon,

    Clever trick! That's the first time I've seen __PARAM1 used for OUTPUT on a function. Makes sense! Sometimes it just takes thinking outside the box. As always, thank you for your gems of advice!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John J. Couture

    San Diego Miramar College
  • JonnyMacJonnyMac Posts: 9,215
    edited 2008-07-22 21:38
    Glad you liked that, John. If you spend as much time as I have looking at the assembly generated by SX/B you will find little shortcuts like this that save the use of an extra variable and, sometimes, a cycle or two.
  • John CoutureJohn Couture Posts: 370
    edited 2008-07-23 00:10
    Yea, I know (for those of you that missed that suttle hint, Jon was saying that I need to wade a little deeper into the pool with my programming) smile.gif Thanks Jon ... I have been resisting the assembler route for long enough (I took many of those courses years ago and found that you have to eat, drink and sleep with the assembler manual for about a month and then >BLINK< a light goes on and enlightment decends upon you).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John J. Couture

    San Diego Miramar College
  • BeanBean Posts: 8,129
    edited 2008-07-23 01:20
    John,
    It wasn't like that for me learning assembler. But it was that way when I was learning "Object Oriented Programming". I just didn't get it for about a month, then one day "Blink" it all made sense.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    "A government big enough to give you everything you want, is big enough to take away everything you·have."·· Thomas Jefferson

    "It is our choices, Harry, that show what we truly are, far more than our abilities."·Dumbledore from Harry Potter

    www.iElectronicDesigns.com

    ·
  • John CoutureJohn Couture Posts: 370
    edited 2008-07-23 06:15
    Funny. I distinctly remember taking an IBM 360 assembler class and one day POW! it dawned on me that the opcodes had a very kool pattern to them and I could predict what the op code was supposed to do just by knowing what bits were lit! It was like one of the "magic eye" pictures and it all became clear! OOP I think just oozed in and it gradually became clear. Then in another class I remember asking if EQU was the same as "=". Ah yes, youth is wasted on the young!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John J. Couture

    San Diego Miramar College
  • ajajackajajack Posts: 26
    edited 2008-07-23 13:38
    JonnyMac said...
    This first problem you have is that you're trying to use the internal oscillator -- this won't work with SERIN (not accurate enough); you must use an external osc source (resonator, etc.).

    I've attached a test program for you to work with; if you have a PDB you can test both sides.
    ·Does it matter the speed of the external oscillator that I use.· Also I have no idea what PDB means.
  • JonnyMacJonnyMac Posts: 9,215
    edited 2008-07-23 14:35
    Since your baud rate is low (4800), you could use a 4 MHz resonator with no trouble. PDB = Parallax Professional Development Board which has sockets for an SX28 and BS2 module on it -- I use it for Stamp to SX testing all the time.
  • BeanBean Posts: 8,129
    edited 2008-07-23 14:40
    John Couture said...
    Then in another class I remember asking if EQU was the same as "=". Ah yes, youth is wasted on the young!
    John,
    · Actually that is very good question (at least with the SX).
    · A name defined with EQU cannot be re-defined later.
    · A name defined with "=" CAN be re-defined later.

    · xxx EQU 5
    · xxx EQU 10 ' Gives an error here

    ·but...

    · xxx = 5
    · xxx = 10 ' No error, this is okay

    Bean.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    "A government big enough to give you everything you want, is big enough to take away everything you·have."·· Thomas Jefferson

    "It is our choices, Harry, that show what we truly are, far more than our abilities."·Dumbledore from Harry Potter

    www.iElectronicDesigns.com

    ·
  • ajajackajajack Posts: 26
    edited 2008-07-23 20:18
    Is there a difference between a resonator and an oscillator? Because I do have some 1 Mhz crystal oscillators lying around or would those not be fast enough?
  • JonnyMacJonnyMac Posts: 9,215
    edited 2008-07-23 20:25
    Those would be fast enough for 4800 baud, I'm sure. If what you mean is 1 MHz crystal (metal can, two pins) then you'll need caps as well (see docs for size). If it's a TTL can oscillator (powered, has four leads) then connect the output to OSC1 and leave OSC2 disconnected -- and do make sure you can disconnect the oscillator from the SX when you're programming; the OSC pins are used by the programming device and a TTL oscillator connected could create an electrical conflict that might kill your SX-Key or Blitz.
  • ajajackajajack Posts: 26
    edited 2008-07-23 23:10
    How should I change my header in sx/b to work with that external oscillator?
  • JonnyMacJonnyMac Posts: 9,215
    edited 2008-07-23 23:35
    Again, the SX documentation is the best reference for that (see page 42). Probably OSCLP1 or OSCLP2.
  • ajajackajajack Posts: 26
    edited 2008-07-24 02:11
    I checked the downloads section on the Parallax site and I can't seem to find the documentation that you are talking about. I don't have any kits from Parallax so I don't have any of the texts I usually just go online and download them. So maybe I am missing something but I just can't seem to find it.
  • JonnyMacJonnyMac Posts: 9,215
    edited 2008-07-24 02:21
    If you go to the SX28 page on the Parallax site you'll find the documentation (PDF).
  • ajajackajajack Posts: 26
    edited 2008-07-24 02:37
    I really cannot find it. I have checked the SX download page in the support section: http://www.parallax.com/tabid/460/Default.aspx and I have check the product page for the SX28. Can you give me a url or something? I am so sorry if it turns out to have been right in front of my face the whole time but I really have tried.
  • JonnyMacJonnyMac Posts: 9,215
    edited 2008-07-24 02:40
    If it had been a snake it would have bit you....

    www.parallax.com/Portals/0/Downloads/docs/prod/datast/SX20AC-SX28AC-Data-v1.6.pdf

    The link to this document can be found on the SX28 product page -- right under the word "Downloads,"
  • ajajackajajack Posts: 26
    edited 2008-07-24 15:26
    Alrighty, I am now clocking my SX with an external TTL oscillator and I have changed the Device Settings in the sx/b code to read:

    DEVICE           SX28, OSCXT2, TURBO, STACKX, OPTIONX
    FREQ             1_000_000
    

    The LED blinked at the beginning of my code like I asked but would not blink again on the arrival of the serial header.· I don't understand what my problem is.
  • Sens-a-DatSens-a-Dat Posts: 44
    edited 2008-07-24 16:02
    Try changing OSCXT2 to OSCXT1 or OSCLP2. From other postings here, I believe I have learned that it helps to not run at the highest possible setting. The OSCLP2 is the lowest setting when operating at 1MHz.

    I hope others will chime in here if there is something else to consider.

    Gary
  • JonnyMacJonnyMac Posts: 9,215
    edited 2008-07-24 16:26
    If the LED is only flashing once then you're not receiving the serial header (your SX program flashes the LED on start-up). I ran your [noparse][[/noparse]unaltered] programs on my PDB and they work as expected, so you might want to check your connections.

    Post Edited (JonnyMac) : 7/24/2008 4:45:30 PM GMT
  • ajajackajajack Posts: 26
    edited 2008-07-24 19:49
    Right now I have my serial wire connected directly from Pin 1 of my BASIC Stamp to the pin on my SX without any pull-up resistor. Should I use one and if so how do I pull-up serial?
  • JonnyMacJonnyMac Posts: 9,215
    edited 2008-07-24 21:14
    I'm using the PDB so ground is common. Do you have ground on your BASIC Stamp circuit connected to ground on your SX circuit? If not, you need to do that. You don't need a pull-up because you're using True mode (driven) which means the serial output pin from the Stamp will be either high or low.
  • ajajackajajack Posts: 26
    edited 2008-07-25 01:33
    Yes that is the problem. As soon as I made the ground common it started working as planned however this is undesirable because I would like to replace the serial wire with a wireless link. It would make no sense to have a wireless serial connection but then require a wired common ground. Is there a way to make this work without having a common ground?
  • JonnyMacJonnyMac Posts: 9,215
    edited 2008-07-25 01:42
    No, you _must_ have ground with a wired connection. But don't worry, once you install your wireless devices you will be free of wires; the receiver will have ground and output connections that will be local with your SX.
  • ajajackajajack Posts: 26
    edited 2008-07-25 16:47
    I have noticed that when wired the led only will flash 3 or 4 times meaning that it only sees 2 or 3 complete headers.· I don't understand why this would be unless it is some sort of timing problem.
  • JonnyMacJonnyMac Posts: 9,215
    edited 2008-07-25 16:52
    I let that program run for more than an hour while I was working on anther project; it works on my desk, and I don't know why you're not having the same success on yours.
  • T&amp;E EngineerT&amp;E Engineer Posts: 1,396
    edited 2008-08-14 15:40
    I'm thinking about a similar project using a master SX28 to transmit serial data to 2 or more SX28 slaves that are connected to 7 segment displays or LCDs or something. I want to be able to connect a keypad to the master SX28 and select which SX28 slave (7 segment or LCD) to send data to·it.

    So if I select slave 1 via the keypad, I want to also send a number to the display like 1234 or something.

    I have seen and used the example·SX code of a keypad using an SX28 as a keypad·driver. Is it reasonable to expect that the sx28·master to the slaves could still·be used as a keypad driver·and master?



    If so, I have seen the example code for the SX Slave, is there any for an SX Master?
Sign In or Register to comment.