Shop OBEX P1 Docs P2 Docs Learn Events
Converting from BS2 to Javelin — Parallax Forums

Converting from BS2 to Javelin

bxgirtenbxgirten Posts: 79
edited 2009-06-30 20:20 in General Discussion
I've never worked with Uart before so I'm having a newbie moment.

The code I'm converting from PBasic, using pin 14:

for speed = 0 to 127
'parms: pin 14, 8 bits no parity non-inverted 9600 baud, [noparse][[/noparse]$80 and 0 are the first 2 bytes, motor number, speed]
serout 14, 84, [noparse][[/noparse]$80, 0, 0, speed]
pause 20
next


Here's how I started my conversion:

static Uart serialLineUart = new Uart(Uart.dirTransmit, CPU.pin14, Uart.dontinvert, Uart.speed9600, Uart.stop8);
for(int i = 0; i < 128; i++) {
serialLineUart.sendString("$80, 0, 0" + new Integer(speed).toString());
}


Am I on the right track with UART? All constructive suggestions welcome.

Thanks!

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-07-27 18:26
    You need to change
    serialLineUart.sendString("$80, 0, 0" + new Integer(speed).toString());
    into
    serialLineUart.sendByte(0x80);
    serialLineUart.sendByte(0x00);
    serialLineUart.sendByte(0x00);
    serialLineUart.sendByte(speed);

    Also note that Uart.stop8 is not necessary. Uart.stop1 will do.

    regards peter
    ·
  • bxgirtenbxgirten Posts: 79
    edited 2008-07-28 13:57
    Thank you, Peter.

    I was planning on trying it yesterday but my 9V conked out on my and I kept getting brown-out conditions. Bought a fresh pair of batteries today so I'll play with this tonight.

    -bxg
  • EmilyPEmilyP Posts: 21
    edited 2009-06-30 19:55
    more conversions ...
    thanks in advanced


    SERIN 1, 16780, [noparse][[/noparse]WAIT(98)]

    Is it possible without an infinite loop + more codez?

    public static void read(){
    int temp = 0;
    while (temp == 0) {
    if (stampRX.byteAvailable()){
    if (stampRX.recieveByte() == 98)
    temp = 1;
    }
    }


    }
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2009-06-30 20:12
    StringBuffer rxChars = new StringBuffer();
    boolean rxMark = false;

    boolean checkRx(int waitchar, int length) {
    · if (rx.byteAvailable()) {
    ··· int c = rx.receiveByte();
    ··· if (!rxMark) {
    ····· if (c == waitchar) rxMark = true;
    ··· }···
    ··· else {
    ····· rxChars.append((char)c);
    ····· if (rxChars.length() == length) return true;
    ··· }
    · }
    · return false;
    }

    From your program just call checkRx() regularly and rxChars will be filled
    after the waitchar has been received. When the method returns true
    you can process rxChars.
    In the mean time you can do other things.

    regards peter
  • EmilyPEmilyP Posts: 21
    edited 2009-06-30 20:20
    Thanks. This was helpful.
Sign In or Register to comment.