Shop OBEX P1 Docs P2 Docs Learn Events
ATTN:Peter (Serial Pin Questions) — Parallax Forums

ATTN:Peter (Serial Pin Questions)

YojimboYojimbo Posts: 40
edited 2005-08-13 02:55 in General Discussion
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

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-08-11 05:08
    See this thread
    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
    ·
  • YojimboYojimbo Posts: 40
    edited 2005-08-11 09:31
    I've been trying just that, bellow is my latest code (hopefully its not too wrong). I seem to be having some trouble getting it to route info from the CMUcamGUI java program (found here http://www.cs.cmu.edu/~cmucam/downloads.html). I changed the CMUcamGUI code so that it transmits @ 9600 baud and the CMUcam1 is set to 9600 baud w/ jumpers. When I listen with a serial port listener I get some weird data symbols. Any ideas? Thanks for your time, I'll play with the serial protocol, see what I can do.

    -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();
    }

    }
    }
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-08-11 13:10
    One thing I noticed, you use the same buffer to append chars from both Terminal and

    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
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-08-11 13:59
    Try attached program.

    I assume the CMUcam baudrate is 9600.

    regards peter
  • YojimboYojimbo Posts: 40
    edited 2005-08-11 21:14
    cool, I will check this out, thank you very very much for your time!!
  • YojimboYojimbo Posts: 40
    edited 2005-08-12 22:46
    well, if what you say is true about the baud rate of the javelin being set at 28800, then that is probably my problem. The java applet CMUcamGUI has some different baud rates it can operate at, but 28800 is not a baud rate it seems to support. I would attempt to alter the code so that it would, but it seems to use a .DLL file named sserial.dll for these method calls so I don't think I can. Do you know of any way I could change the baud rate of the javelin stamp itself? Or perhaps a secret java guru way of editing the .dll or something? the method is called from serialComm.java/class and serialPort.java/class (http://www.cs.cmu.edu/~cmucam/downloads.html). I hope someone has some insight, as I have hit a heafty wall I think. Thanks for your time.

    -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.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-08-13 02:55
    The only way to have other baudrates is to dedicate two I/O pins for serial connection

    to the PC (via a level shifter like the MAX232).

    regards peter
Sign In or Register to comment.