Shop OBEX P1 Docs P2 Docs Learn Events
More than 3 Uarts on a Javelin? — Parallax Forums

More than 3 Uarts on a Javelin?

Shawn ReedShawn Reed Posts: 6
edited 2005-02-07 21:10 in General Discussion
All,

I added a SureLink RF module to my robot this weekend and after getting a test program working I tried to integrate the code into the existing code. Every time I tried I could not get the serial Uart to my motor controller to work. (existing working code) Sure enough if I took out the two new Uarts for the SureLink, the motor Uarts would work again.

After some experimenting I found it did not matter which Uarts only that there were no more than 3. I confirmed there were only 4 total VPs while in debug but still wouldn't work. (Three is no problem) I tried slower buad rates on all Uarts but that did not seem to matter. I also tried changing the order they were instantiated but that didn't seem to matter either.

This works:

import stamp.core.*;
import stamp.peripheral.io.I2C;
import stamp.peripheral.controller.motor.MotorMindC;
import stamp.peripheral.sensor.compass.CMPS03;

public class demoMMC_SureLink {

  //I2C bus pins
  final public static int SDAPIN          = CPU.pin4;
  final public static int SCLPIN          = CPU.pin5;

  //MotorMindC pins & Address
  final public static int MMC_TXPIN       = CPU.pin12;
  final public static int MMC_RXPIN       = CPU.pin13;
  final public static int MMC_ADDRESS     = 1;

  static I2C i2c = new I2C(SDAPIN, SCLPIN);

  static CMPS03 compass = new CMPS03(i2c);

  final static int RF_TX_PIN = CPU.pin7;
  final static int RF_RX_PIN = CPU.pin8;
  final static int RF_LINK_PIN = CPU.pin9;
  public static Uart txUart = new Uart( Uart.dirTransmit,
                                        RF_TX_PIN,
                                        Uart.invert,
                                        Uart.speed19200,
                                        Uart.stop1 );

  static MotorMindC mmc = new MotorMindC(MMC_TXPIN,MMC_RXPIN,(char)MMC_ADDRESS);

  static int heading;

  public static void main() {
    while (true) {
      heading = compass.getHeading();
      if (heading < 80 || heading > 100) {
        if (heading > 90 && heading < 270) {
          //turn left
          mmc.rotateLeft();
        } else {
          //turn right
          mmc.rotateRight();
        }
      } else {
        mmc.stop();
      }
    }
  }
}




This will not:

import stamp.core.*;
import stamp.peripheral.io.I2C;
import stamp.peripheral.controller.motor.MotorMindC;
import stamp.peripheral.sensor.compass.CMPS03;

public class demoMMC_SureLink {

  //I2C bus pins
  final public static int SDAPIN          = CPU.pin4;
  final public static int SCLPIN          = CPU.pin5;

  //MotorMindC pins & Address
  final public static int MMC_TXPIN       = CPU.pin12;
  final public static int MMC_RXPIN       = CPU.pin13;
  final public static int MMC_ADDRESS     = 1;

  static I2C i2c = new I2C(SDAPIN, SCLPIN);

  static CMPS03 compass = new CMPS03(i2c);

  final static int RF_TX_PIN = CPU.pin7;
  final static int RF_RX_PIN = CPU.pin8;
  final static int RF_LINK_PIN = CPU.pin9;
  public static Uart txUart = new Uart( Uart.dirTransmit,
                                        RF_TX_PIN,
                                        Uart.invert,
                                        Uart.speed19200,
                                        Uart.stop1 );

   public static Uart rxUart = new Uart( Uart.dirReceive,
                                         RF_RX_PIN,
                                         Uart.invert,
                                         Uart.speed19200,
                                         Uart.stop1 );


  static MotorMindC mmc = new MotorMindC(MMC_TXPIN,MMC_RXPIN,(char)MMC_ADDRESS);

  static int heading;

  public static void main() {
    while (true) {
      heading = compass.getHeading();
      if (heading < 80 || heading > 100) {
        if (heading > 90 && heading < 270) {
          //turn left
          mmc.rotateLeft();
        } else {
          //turn right
          mmc.rotateRight();
        }
      } else {
        mmc.stop();
      }
    }
  }
}




For now I have remove the second Uart from the motor controller so I have no feedback from it (not critical for now) so I can use two Uarts for the SurLink modules.

Any thoughts?


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Shawn

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-02-07 07:11
    You should be able to run 4 uarts, assuming no other VP's

    are created (like ADC, timer etc.)

    Does the main() start? (print message before while to know)

    What happens if you put the rxUart assignment in main

    before the while?

    public·static·void·main()·{
    ····rxUart·=·new·Uart(·Uart.dirReceive,
    ·········································RF_RX_PIN,
    ·········································Uart.invert,
    ·········································Uart.speed19200,
    ·········································Uart.stop1·);

    ·· System.out.println("test program");

    ···while·(true)·{
    ······heading·=·compass.getHeading();
    ······if·(heading·<·80·||·heading·>·100)·{
    ········if·(heading·>·90·&&·heading·<·270)·{
    ··········//turn·left
    ··········mmc.rotateLeft();
    ········}·else·{
    ··········//turn·right
    ··········mmc.rotateRight();
    ········}
    ······}·else·{
    ········mmc.stop();
    ······}
    ····}

    }




    regards peter
  • Rob v.d. bergRob v.d. berg Posts: 89
    edited 2005-02-07 11:53
    Hi Shawn,

    This sounds like my problem to. In the·manual of the Motor Mind C·is an·inter-character time of 2 msec: see page 17 of the MMC manual.· www.solutions-cubed.com
    The inter-character time is the time between successive characters (bytes) in the same packet.· The maximum time allowed is 2 milliseconds for the MMCCP.
    Through·the nr of VP in your program, the time between each sending character can·be more the 2 msec. When you stop one or more VP's before sending characters to the MMC, you can change that time a bit.·After sending, you·can start the VP's
    I have solved it like this:
    · static void Init_MMC() {
    ··· rxUart_1.stop();
    ··· rxUart_2.stop();
    ··· RepMMC = MMC.WritePWMSTEP(1);
    //··· RepMMC = MMC.ReadREGNR(1);
    //··· RepMMC = MMC.WriteDBD(1); //werkt
    //··· RepMMC = MMC.WriteBRM(0);· //werkt
    ··· rxUart_1.start();
    ··· rxUart_2.start();
    ··· }
    Regards Rob van den Berg.
  • Shawn ReedShawn Reed Posts: 6
    edited 2005-02-07 21:10
    Thank for the quick replys!

    Peter, yes the main is executing in fact the other serial device is functioning so I belive Rob has it nailed. I'll confirm this when I get home this evening.

    In case someone searches on this later here is the exact text from the Rev3 MMC documentation:

    "4.3 Error Detection / Communication Requirements
    Error detection is accomplished by inspection of the received data and making sure that the data was
    received in a timely fashion.

    Inspection of the data packets will be performed by…
    1) verifying that all elements of the packet are present
    2) making sure that the message is the correct length
    3) verifying the checksum
    4) verifying that the message is supported by the Slave
    5) testing all values with limited range

    Two time periods are monitored for error detection. They are…
    1) inter-character time
    2) response time

    The inter-character time is the time between successive characters (bytes) in the same packet. The
    maximum time allowed is 2 milliseconds for the MMCCP.

    The response time is the time from when the Master sends the last character of the Command Packet, to
    when the Master receives a response from the Slave. The maximum allowable response time is 7
    milliseconds. Typical response time is 5ms."

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Shawn
Sign In or Register to comment.