Shop OBEX P1 Docs P2 Docs Learn Events
Javelin and SureLink RF Module (#30065) — Parallax Forums

Javelin and SureLink RF Module (#30065)

Paul RingPaul Ring Posts: 16
edited 2005-01-05 16:35 in General Discussion
Did anyone tried to use SureLink RF modules?

I'm trying to send data between 2 Javelin Stamps using SureLink RF modules. On the one side I have a Javelin connected to the Javelin Stamp Demo board and on the other side a Javelin Stamp module connected to a Board of Education (The distance between the 2 RF modules is ~10 feet). I wired the RF modules as described in the manual (for the SureLink RF module) on page 9 (PointA and PointB). Then I tried to "translate" the BASIC code to Javelin Java using 2 UARTs - one for sending and one for receiving instead of the SERIN and SEROUT BASIC commands. I'm using the same speeds on both sides (9600 bps).

Here is the code:

Point A

import stamp.core.*;

public class PointA
{
  final static int SERIAL_TX_PIN = CPU.pin5;
  final static int SERIAL_RX_PIN = CPU.pin6;

  static StringBuffer buffer = new StringBuffer(128);
  static char c;

  static void bufferMessage( Uart rx )
  {
    c = 0xff;
    int i = 0;
    while (c != '\r' && c != '\n')
    {
      if(rx.byteAvailable())
      {
        c = (char)rx.receiveByte();
        if (c != '\r' && c != '\n')
        {
          System.out.println("" + i);
        }
      }
    }
  }

  public static void main()
  {

    CPU.delay( 100 );
    CPU.writePin( CPU.pin15, false );

    CPU.writePin( CPU.pin5, true );
    Uart txUart = new Uart( Uart.dirTransmit, SERIAL_TX_PIN, Uart.dontInvert,
                            Uart.speed9600, Uart.stop1 );



    Uart rxUart = new Uart( Uart.dirReceive, SERIAL_RX_PIN, Uart.dontInvert,
                            Uart.speed9600, Uart.stop1 );



    while ( !CPU.readPin(CPU.pin15))
    {
      int i = 0;
    }

    do
    {
      buffer.clear();

      while ( true )
      {
        txUart.sendByte((byte)'a');
        CPU.delay( 1000 );
      }

    }
    while (true);
  }

}




Point B

import stamp.core.*;

public class PointB
{
  final static int SERIAL_TX_PIN = CPU.pin5;
  final static int SERIAL_RX_PIN = CPU.pin6;

  static StringBuffer buffer = new StringBuffer(128);
  static char c;

  static void bufferMessage( Uart rx )
  {
    c = 0xff;
    int i = 0;
    while (c != '\r' && c != '\n')
    {
      if(rx.byteAvailable())
      {
        c = (char)rx.receiveByte();
        if (c != '\r' && c != '\n' && c != 0 )
        {
          buffer.append(c);
          System.out.print( buffer.toString() );
          buffer.clear();
        }
      }
    }
  }

  public static void main()
  {

    CPU.delay( 100 );
    CPU.writePin( CPU.pin5, false );

    CPU.writePin( CPU.pin5, true );

    Uart txUart = new Uart( Uart.dirTransmit, SERIAL_TX_PIN, Uart.dontInvert,
                            Uart.speed9600, Uart.stop1 );

    Uart rxUart = new Uart( Uart.dirReceive, SERIAL_RX_PIN, Uart.dontInvert,
                            Uart.speed9600, Uart.stop1 );

    while ( !CPU.readPin(CPU.pin15))
    {
      int i = 0;
    }

    do
    {
      buffer.clear();

      try
      {
        // Now, wait for the Point A to send data
        bufferMessage(rxUart);
      }
      catch( Exception ex )
      {

      }

      // Send the message from us
      buffer.append("PointB\r");
      txUart.sendString( buffer.toString() );
      CPU.delay(1000);

      System.out.println( buffer.toString() ); // PE.041226
      CPU.delay(1000);
    }
    while (true);
  }
}





So the thought is to send character 'a' from Point A to Point B and to display the incomming message on the System.out if we're able to receive anything - which we are not. I tried many things - like using different speeds and I also checked the wirerings 4 times (just to make sure I didn't missed anything). Everything seems to be OK.

I'm using a "LINK" pin which is turning high if the RF modules can find each other. And they do find each other, which I'm sure about, because if I turn off one of the RF modules and debugging the Javelin, the code execution loops in the while loop below waiting for pin15 to turn high.

    while ( !CPU.readPin(CPU.pin15))
    {
      int i = 0;
    }




If I turn on the RF module then the execution continues past the while(...) loop. Debugging in the Point B code reveals that "some data" is received even if the other RF module is turned off. The only character received by Point B is '0' - why? How can this be possible?

Since the RF modules do find each other - the problem might be between the Javelin(s) and the RF module(s). Is it correct to send serial data using the UARTs as I did above?

Here is the BASIC code for Point B
The code for Point A is almost the same...
   Link      PIN   15
   DOut     PIN    5
   DIn       PIN    6


   Baud    CON   84+$4000

   X         VAR    Byte

Initialize:
   PAUSE 250
   HIGH   5

Main:
   DEBUG ".", CR
   IF LINK = 0 THEN Main
   DEBUG "Linked", CR

DO
   SEROUT   DOut, Baud, [noparse][[/noparse]66]
   SERIN     Din, Baud, 500, NoData, [noparse][[/noparse]x]
   DEBUG    x
Nodata:
LOOP




Considering the BASIC code and the Javelin code...did I do anything wrong?
I've done some research on google and I came across some very interesting postings from the old Parallax discussion forums from 2003.
Here is the address:

-->Old Forums

Apparently someone else had the same problem using serial communications and the UART class.

Have anyone any idea what the problem might be?

Post Edited (Paul Edfeldt) : 12/31/2004 11:31:38 AM GMT

Comments

  • edited 2005-01-05 03:01
    Try these programs instad:

    PointA.java
    PointB.java

    Point A should send the character ‘A’ to the Point B. If the Point B receives an ‘A’, it will reply with a ‘B’.
    Point A will track the number of ‘A’ characters it has sent, and it will display a ‘B’ echo whenever it receives the echo from Point B.

    IMPORTANT: The Javelin Stamps are connected to the Surelink modules the same way they are connected to the BASIC Stamps·on pages 8 and 9 of the SureLink Manual rev1.1 (pdf).· This manual is available for free download from the SureLink 900 MHz RF Module·product page.
    Hopefully this will help get you started.

    Post Edited (Andy Lindsay) : 1/5/2005 3:38:10 AM GMT
  • Paul RingPaul Ring Posts: 16
    edited 2005-01-05 16:35
    Hello,

    Thanks for the code examples you've sent me. I tried them and I'm sorry to say this but it didn't worked. So, I disassembled everything and started from the "beginning", reconnecting everything according to the manual - and guess what! It worked after that.
    I might add that I checked the wirerings ~10 times and I couldn't find any wrong connections.
    I guess the problem was a wire (that didn't worked), but I don't know which one. Now I'm happy that it works anyway.

    Thanks for your help.
    Regards
    /Paul

    smile.gif
Sign In or Register to comment.