Shop OBEX P1 Docs P2 Docs Learn Events
TX433 and RX433 — Parallax Forums

TX433 and RX433

Jon KeinathJon Keinath Posts: 146
edited 2005-12-03 20:44 in General Discussion
I have been trying to interface the Transmitter and Receiver that is available here... http://www.rentron.com/Stamp_RF.htm It has Basic stamp code, and I have been able to convert most of it to the javelin, but it doesn't seem to be working properly.

If I send codes right after another it will work for a while,(it occasionaly receives a wrong byte, I can live with this), but if I put any sort of pause it only receives the first properly, then returns only junk bytes.

Is there a way to use the serin, WAIT modifier in the Javelin?

Here is the RX code:
public class  RFtx
  {
  public static char data = 'o';
  public static char sync;
  public static char junk;
  public static int txPin = CPU.pin2;//transmit pin
  public static int loop = 1;
  public static boolean flip = true;
  public static Uart txUart = new Uart(Uart.dirTransmit, //Uart for sending data
                                       txPin,            //to RF transmitter
                                       Uart.dontInvert,
                                       Uart.speed2400,
                                       Uart.stop1);


  public static void main()
    {
    loop = 0;
    sync = 'a';  //sycronizes tx and rx
    junk = 'z';  //warm up byte
    while (true)
      {
      loop++;
      data = 'o';
      if (loop%3 == 0) data = 'r';
      if (loop%3 == 1) data = 'g';
      if (loop%3 == 2) data = 'b';

      txUart.sendByte(junk);
      txUart.sendByte(sync);
      txUart.sendByte(data);
      CPU.delay(2500);                
      System.out.println(data);

      }
    }
 }



And here is the TX code:
public class RFrx
  { 

   public static int rxPin = CPU.pin8;
     public static Uart rxUart = new Uart(Uart.dirReceive, //Uart for sending data
                                       rxPin,            //to RF transmitter
                                       Uart.dontInvert,
                                       Uart.speed2400,
                                       Uart.stop1);


   public static char sync;
   public static int data;
   public static void main()
    {
    color(1,1,1);  //turn "off" all three colors.
    while (true)
      {
        sync=(char)rxUart.receiveByte();  //wait for sync byte
        System.out.println(sync);
        if (sync =='a')
          {

          data = rxUart.receiveByte();       //receive data byte
          System.out.println(data);
          switch (data)
            {
            case 'b':
              blue();
              color(red,green,blue);  //these commands are simple subroutines that update 3 pwm uarts
              break;
            case 'r':
              red();
              color(red,green, blue);
              break;
            case 'g':
              green();
              color(red,green,blue);
              break;
              }
            }

           }
        }
      }

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-12-02 05:03
    Why have you chosen sync = 'a' (0x61) instead of sync = 'A' (0x41) as in the BS example?
    Why have you chosen sync = 'z' (0x7A) instead of sync = 126 (0x7E) as in the BS example?
    Try the BS values: it may make a difference.
    regards peter


    Post Edited (Peter Verkaik) : 12/2/2005 5:32:57 AM GMT
  • Jon KeinathJon Keinath Posts: 146
    edited 2005-12-02 17:40
    There was no reason to why I chose something other than what was used in the BS program. I thought that it would only have to be the same in both programs. I will try the BS values tonight when I get home.

    Upon further investigation I think what is happening is the receiver is missing a bit somewhere, and that is where all the garbage values are comming from.
    If I understand the WAIT modifier for the BS's Serin it will solve this problem my waiting for the sequence '01000001' ('A') and then starts the next byte after that. The Javelins UART only receives a byte at a time and if one of the bits is missing a different value is returned.. I'll try to explain this with some ascii art...

    What data string should look like:(bytes divided by -'s)(assuming BS example values)
    
                    Random Bytes-126     -   'A'  - Data('r')
                    000000000000-01111110-01000001-01110010
    Javelin UART    |------||--- ---||--- ---||--- ---||---
    STAMP Serin     iiiiiiiiiiii iiiiiiii |------| |------|   
    
    (i = ignore) (| = beginning and end of a byte)
    
    


    Based on this I can see why I get it to work sometimes, but not others.

    This is how I assume it is working, I may or may not be correct in my assumptions. (Do my assumptions make sense?)
    Does this mean that "all" I have to do is build some code that looks at the data steam a bit at a time?

    Thanks for your help
    -Jon
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-12-02 19:50
    You have to take into account the startbit and stopbit that surrounds each byte. It is unlikely
    that bits move to other bytes. You already wait for sync before continuing but you could
    rewrite your while (true) loop to reflect WAIT more closely. Is also less code.

    ··public·static·void·main()·{ //main receive
    ····color(1,1,1);··//turn·"off"·all·three·colors.
    ··· while·(true)·{
    ······do {
    ········data=(char)rxUart.receiveByte();··//wait·for·sync·byte
    ······} while (data != sync);
    ······data·=·rxUart.receiveByte();·······//receive·data·byte = byte following sync
    ······switch·(data)·{
    ········case·'b':·blue();
    ····················color(red,green,blue);··//these·commands·are·simple·subroutines·that·update·3·pwm·uarts
    ··················· break;
    ········case·'r':·red();
    ··················· color(red,green,·blue);
    ··················· break;
    ········case·'g':·green();
    ··················· color(red,green,blue);
    ··················· break;
    ······}
    ····}
    ··}

    regards peter
    ·
  • Jon KeinathJon Keinath Posts: 146
    edited 2005-12-02 20:27
    Oh, Yeah...Forgot about them(start and stopbits)
  • Jon KeinathJon Keinath Posts: 146
    edited 2005-12-03 03:29
    I tried using the BS values, but it didn't change anything.

    But I did discover one thing, if I send bytes right after one another (remove the delay(2500) line from my tx code), it will recive the correct data every time..(well 99 out of 100) or so, but if I have the delay anything over about 200 it will only receive the first one, then a few (1-2 out of 100) after that.

    I have attached the current stripped down code that I have been using to test these.

    if i run it with out a delay, the terminal returns
    ~Ab
    ~Ab
    ~Ab
    ...
    and with a delay... it's just a bunch of random characters with an occasional ~Ab in it.



    If anyone has any ideas, they would be greatly appreciated.

    Thanks,
    -Jon

    Post Edited (Jon Keinath) : 12/3/2005 3:33:41 AM GMT
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-12-03 08:47
    The text with the BS example says the junk byte is used to stabilize the

    receiver's oscillator. Having a gap in the transmission (your delay) may cause

    this oscillator to destabilize. Try sending more junk bytes before the sync and data.

    These extra junk bytes give time to stabilize the oscillator. Try to send

    junk,junk,junk,sync,data and see if that improves your reception.

    regards peter
  • Jon KeinathJon Keinath Posts: 146
    edited 2005-12-03 20:44
    Thanks for the help Peter, that was what it needed, I added 5 Junk bytes, and it works like a champ. (it misses the first 2-3 junk bytes each time)

    THANKS Again!
    -Jon
Sign In or Register to comment.