Shop OBEX P1 Docs P2 Docs Learn Events
Javelin and TINI (UART transmit problems) — Parallax Forums

Javelin and TINI (UART transmit problems)

Paul RingPaul Ring Posts: 16
edited 2004-12-28 07:39 in General Discussion
I have a really weird problem when I try to connect my TINI (Systronix TStik) to the Javelin Stamp Demo Board using the COM port.
What I'm doing is that I'm connecting the Serial0 of the TStik using a serial cable and a NULL modem adapter to the COM port of the Javelin Stamp Demo Board.

On the TStik side, I have a java program that opens the serial0 port and creates an input stream an output stream.
On the Javelin side, I have a small program that reads the data comming to the COM port and displays it using System.out.println(...) and then replies a short string back to the COM port.

When I'm sending over strings (byte arrays) to Javelin from the TStik I can see that the data arrives, but when I try to send data (a short string) back to the TStik nothing happens on the TStik side. The data never arrives and the message SerialPortEvent.DATA_AVAILABLE is never triggered...if I keep sending data this way, the send buffer in the UART class on the Javelin side will eventually fill up and Javelin will be blocked in the sendByte(...) function (see the UART.java).

I'm not using hardware handshaking (not on the TStik nor Javelin). My question is...does anyone know why Javelin isn't sending the data using the transmit UART?

I tried different things the past days without getting around this problem. I tried to connect the TINI to my computers COM port and I was able to send and receive data without any problems. I did the same with the Javelin...without having any problems either. It seems there is nothing wrong with the serial cable and I don't think there can be anything wrong with the NULL modem adapter either.

Why is the UART blocked? Does it wait for some kind of handshaking or what?

Please help me with this

Here is the code:
TINI code:



package SimpleReadWrite;

import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.util.TooManyListenersException;
import com.dalsemi.system.TINIOS;
import javax.comm.*;

public class SimpleReadWrite implements Runnable, SerialPortEventListener {

    static String DEFAULT_PORT = "serial0";

    InputStream  in;
    OutputStream out;
        SerialPort serialPort;
        
    public static void main(String[noparse][[/noparse]] args) 
        {
        String portname = DEFAULT_PORT;


        try 
                {
            CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(portname);
            if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) 
                        {
                SimpleReadWrite srw = new SimpleReadWrite(portId);
            }
            else 
                        {
                System.err.println(portname + " is not a serial port");
                System.exit(1);
            }
        }
        catch (NoSuchPortException e) {
            System.err.println("No such port: " + portname);
            System.exit(1);
        }
        catch (PortInUseException e) {
            System.err.println("Port in use: " + portname);
            System.exit(1);
        }
    }

  public SimpleReadWrite(CommPortIdentifier portId) throws PortInUseException 
    {
        try 
        {
            serialPort = (SerialPort) portId.open("SimpleReadWrite", 5000);
                                                             
                    in  = serialPort.getInputStream();
                    out = serialPort.getOutputStream();
                    serialPort.addEventListener(this);
                    serialPort.notifyOnCTS(true);
                    serialPort.notifyOnDSR(true);
                    serialPort.notifyOnRingIndicator(true);
                    serialPort.notifyOnCarrierDetect(true);
                    serialPort.notifyOnOverrunError(true);
                    serialPort.notifyOnParityError(true);
                    serialPort.notifyOnFramingError(true);
                    serialPort.notifyOnBreakInterrupt(true);
                    serialPort.notifyOnDataAvailable(true);
                    serialPort.notifyOnOutputEmpty(true);
            
                    serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
                                         
                    //System.out.println("Before getRTSCTSFlowControlEnable=" + TINIOS.getRTSCTSFlowControlEnable(0) );
                    // Enables or disables RTS/CTS Flow Control for a specified serial port.
                    TINIOS.setSerial(TINIOS.SERIAL_SET_RTSCTS_FLOW_CONTROL, 0, false );
                    
                    //System.out.println("After getRTSCTSFlowControlEnable=" + TINIOS.getRTSCTSFlowControlEnable(0) );
                    
                                Thread readerThread = new Thread(this);
                                readerThread.start();
                        }
                        catch (IOException e) {
                                System.err.println("Problem opening streams");
                                System.exit(1);
                        }
                        catch (TooManyListenersException e) {
                                System.err.println("Too Many Listeners");
                                System.exit(1);
                        }
                        catch (UnsupportedCommOperationException e) {
                                System.err.println("Problem setting port parameters");
                                System.exit(1);
                        }
    }

    public void run() 
    {
        byte character;
        byte[noparse][[/noparse]] bData = new byte[noparse][[/noparse]100];
        String str = "";
        
        try 
        {
            while (true) 
            {
                bData = new byte[noparse][[/noparse]100];
            
                //character = (byte) System.in.read();
                int nBytes = System.in.read(bData);
                str = new String(bData);
                System.out.println("Sending data:" + str);
                str += "\n\r";
                out.write(str.getBytes());
        
                out.flush();
                                
            }
            catch (IOException e) 
            {
                // Terminate thread
            }
        }
    }
    public void serialEvent(SerialPortEvent event) 
    {
        switch (event.getEventType()) {
            case SerialPortEvent.BI:
                break;
            case SerialPortEvent.OE:
                break;
            case SerialPortEvent.FE:
                break;            
            case SerialPortEvent.PE:
                break;
            case SerialPortEvent.CD:
                break;
            case SerialPortEvent.CTS:
                break;
            case SerialPortEvent.DSR:
                break;
            case SerialPortEvent.RI:
                break;
            
            case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
                break;
            case SerialPortEvent.DATA_AVAILABLE:
                byte[noparse][[/noparse]] readBuffer = new byte[noparse][[/noparse]20];
                try 
                {
                    while (in.available() > 0) 
                    {
                        int numBytes = in.read(readBuffer);
                    }
                    System.out.print(new String(readBuffer));
                }
                catch (IOException e) 
                {
                    // Terminate handling this event on read error
                }
                break;
            default:
                System.out.print("Unknown SerialPortEvent type = " + event.getEventType());
                break;
        }
    }
}



Javelin code:

import stamp.core.*;

public class HyperTermCOM {                         // COM Port (9-pin serial)

  final static int SERIAL_TX_PIN = CPU.pin0;        //     2
  final static int SERIAL_RTS_PIN = CPU.pin1;       //     7
  final static int SERIAL_CTS_PIN = CPU.pin2;       //     8
  final static int SERIAL_RX_PIN = CPU.pin3;        //     3

  /*
  static Uart txUart = new Uart( Uart.dirTransmit, SERIAL_TX_PIN, Uart.dontInvert,
                          SERIAL_RTS_PIN, Uart.dontInvert, Uart.speed9600,
                          Uart.stop1 );


  static Uart rxUart = new Uart( Uart.dirReceive, SERIAL_RX_PIN, Uart.dontInvert,
                          SERIAL_CTS_PIN, Uart.dontInvert, Uart.speed9600,
                          Uart.stop1 );

  */


  static StringBuffer buffer = new StringBuffer(128);
  static char c;

  static void bufferMessage( Uart rx )
  {
    c = 0xff;
    while (c != '\r')
    {
      if(rx.byteAvailable())
      {
        c = (char)rx.receiveByte();
        buffer.append(c);
      }
    }
  }                                                  // end bufferMessage

  public static void main()
  {

    Uart txUart = new Uart( Uart.dirTransmit, SERIAL_TX_PIN, Uart.dontInvert,
                            SERIAL_RTS_PIN, Uart.speed9600,
                            Uart.stop1 );

    Uart rxUart = new Uart( Uart.dirReceive, SERIAL_RX_PIN, Uart.dontInvert,
                            SERIAL_CTS_PIN, Uart.speed9600,
                            Uart.stop1 );

    do
    {
      buffer.clear();
      bufferMessage(rxUart);

      if ( txUart.sendBufferEmpty() )
        System.out.println("The send buffer is empty");

      txUart.sendString("I\n\r");

      System.out.println( buffer.toString() ); // PE.041226
      int i = 0;
    }
    while (true);
  }

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2004-12-28 07:05
    Hi,

    You say you don't use hardware flow control. In the javelin code however

    you specify handshake pins in the Uarts.

    You should use

    Uart txUart = new Uart(Uart.dirTransmit,SERIAL_TX_PIN,Uart.dontInvert,Uart.speed9600,Uart.stop1);

    and the same applies to rxUart



    regards peter
  • Paul RingPaul Ring Posts: 16
    edited 2004-12-28 07:39
    Hi Peter,

    And thank you...you solved my problem(s).
    I feel so stupid. blush.gif I don't understand how I could miss such a thing.
    Thank you once again.

    Regards
    Paul
Sign In or Register to comment.