ATTN:Peter (Serial Pin Questions)
Yojimbo
Posts: 40
ok, so I am trying to read/write to the SIN and SOUT pins like I would pins 0 - 15 using the UART object. Is there any way to do this? The UART objects only seem to accept CPU.pin0 - CPU.pin15 which corrospond to the physical pins 5 - 20, but I need to read SIN (pin physical 1) and write on SOUT (pin 2). Any ideas? I could really use some help, I'm at the end of my rope! heh. Thanks for your time.
-Sean
-Sean
Comments
http://forums.parallax.com/showthread.php?p=527910
In short: you use Terminal.byteAvailable() and Terminal.getChar() to receive bytes
via the Sin pin, you use System.out.print() and System.out.println() to transmit
bytes via the Sout pin.
On the PC (or other MCU) a program must apply to the Javelin protocol
regarding the Sin and Sout pins. The baudrate is fixed to 28800.
regards peter
·
-Sean
import stamp.core.*;
import java.lang.*;
public class TestCam {
static Uart txUartCam = new Uart(Uart.dirTransmit,CPU.pin7,Uart.dontInvert,Uart.speed9600,Uart.stop1);
static Uart rxUartCam = new Uart(Uart.dirReceive,CPU.pin9,Uart.dontInvert,Uart.speed9600,Uart.stop1);
static StringBuffer buffer = new StringBuffer(1024);
static char c;
public static void toCamera(){
while(Terminal.byteAvailable()){
c = (char)Terminal.getChar();
buffer.append(c);
if (c == '\r'){
txUartCam.sendString(buffer.toString());
buffer.clear();
CPU.delay(1000);
}
}
}
private static boolean ack(){
String ack;
String nck;
ack = "ACK";
nck = "NCK";
if (buffer.equals(ack) || buffer.equals(nck)){
return true;
}
else{
return false;
}
}
public static void toGUI(){
while(rxUartCam.byteAvailable()){
c = (char)rxUartCam.receiveByte();
buffer.append(c);
if (c == '\r'){
if(ack()){
System.out.println(buffer.toString());
buffer.clear();
CPU.delay(1000);
}
else{
txUartCam.sendString(buffer.toString());
buffer.clear();
CPU.delay(1000);
}
}
}
System.out.println(buffer.toString());
buffer.clear();
//System.out.println(buffer.toString());
}
public static void main(){
while(true){
toCamera();
toGUI();
c = 'F';
buffer.clear();
}
}
}
CMUcam. Better to use seperate buffers, so messages from both devices do not interfere
with each other. Then messages received from Terminal (into buffer) can be send to CMUcam,
messages from CMUcam (into buffer2) can be send to Terminal using System.out.print().
regards peter
I assume the CMUcam baudrate is 9600.
regards peter
-Sean
P.S. Happen to know any resources for coding a neural network with the Javelin? Some examples would be invaluable to pull apart for a future project of mine.
to the PC (via a level shifter like the MAX232).
regards peter