Converting from BS2 to Javelin
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!
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
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
·
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
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;
}
}
}
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