Shop OBEX P1 Docs P2 Docs Learn Events
Serial Communication without terminal — Parallax Forums

Serial Communication without terminal

timmstatimmsta Posts: 6
edited 2009-01-07 13:43 in Propeller 1
Hi Everybody,

I'm trying to do an serial communication with the FullDuplexSerialPlus object and processing (java based programming tool -> processing.org). my problem is, that i can receive data from the propellor, but when sending, it's not understood by the prop. i guess it's a syntax problem, but i'm not exactly shure what the FullDuplexSerialPlus is expecting as e.g. an end signal. anybody got an idea, what i could try?

cheers

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-01-06 16:04
    The strings processed by the additional routines in the Extended Full Duplex Serial object are assumed to end with a carriage return (13) character. If you need additional information or help, please attach a copy of your Propeller program to your message. It's difficult to give advice without adequate information about the circumstances.
  • RiJoRiRiJoRi Posts: 157
    edited 2009-01-06 22:04
    When debugging serial comms, I first make sure the parameters are correct (Baud rate, word length, parity, stop bits). I also (if possible) use a SLOW baud rate -- think 300 baud. I use a terminal or terminal program on the computer -- HyperTerm usually works. Find a way to show what the Propeller thinks it is getting -- through the TV or a second monitor. Finally, if an o'scope is available, hook it up to the Computer --> Prop. line, and enter capital 'U's. The ASCII value for U is 0x55, which gives a nice square wave so you can check the timing, etc.

    HTH,
    --Rich
  • timmstatimmsta Posts: 6
    edited 2009-01-07 09:26
    Hello,

    thanks or replying! I did check the baud rate and the hyperterminal, and it's all working nice with that. To just simply check the communication out, I made the code as simply as possible:

    CON

    _clkmode = xtal1 + pll16x ' System clock → 80 MHz
    _xinfreq = 5_000_000


    OBJ

    Debug : "FullDuplexSerialPlus" ' Display object to use with HyperTerminal


    PUB Init

    'Configure ctra module.
    ctra[noparse][[/noparse]30..26] := %00100 ' Set ctra for "NCO single-ended"
    ctra[noparse][[/noparse]8..0] := 27 ' Set APIN to P27
    frqa := 0 ' Don't send a tone yet.
    dira[noparse][[/noparse]27]~~ ' I/O pin to output
    dira[noparse][[/noparse]9] := 1

    'Start FullDuplexSerialPlus.
    Debug.start(31, 30, 0, 9600)
    waitcnt(clkfreq * 2 + cnt)

    SerialTest

    PUB SerialTest | incomming

    'dira[noparse][[/noparse]9] := 1

    repeat
    incomming := Debug.getDec
    Debug.Str(String(10, 13, "I got: "))
    Debug.Dec(incomming)

    So it's simply just replying what it's getting. Exactly the same thing i'm doing with processing. as the FullDuplexSerialPlus is waiting for a signal, processing is just writing in a one second loop, and simply just prints out everything that comes in:

    import processing.serial.*;

    Serial myPort; // Create object from Serial class
    int val; // Data received from the serial port

    void setup()
    {
    size(200, 200);

    String portName = Serial.list();
    myPort = new Serial(this, portName, 9600);
    println(Serial.list());
    delay(1000);
    }

    void draw()
    {

    while (myPort.available() > 0) {
    myPort.write(100);
    myPort.write("13");
    String inBuffer = myPort.readString();
    if (inBuffer != null) {
    println(inBuffer);
    }
    delay(1000);
    }
    }

    (Don't now if this code helps you as it is kind of specific) As I said both codes are very rudamental, and things are working with the hyperterminal. I guess it's more on the processing side...

    cheers
  • timmstatimmsta Posts: 6
    edited 2009-01-07 11:47
    I just figured out that it's not the sending, but seems to be the opening of the port...

    if i'm just looking if the port is open, like:

    if (myPort.available() > 0){
    println("gogogo!");
    delay(10009;
    }

    it doesn't do anything at the first time. but, when getting impatient disconnect + connect again i just get just bad things from the chip like:

    œ4m”¶h”œ<m”¶h”œ4m”¶h”œ4m”¶h”œ4m”–h”œ<m”–h”œ4m”–h”œ4m”–h”œ4m”–h”¶h”–h”œ4m ”–h”œÚ”–h”œÚ”–

    but constantly - i have to reboot the chip in order to calm it down again...

    any idea?
    cheers
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-01-07 12:01
    Hello timmsta,

    the forum can help if you attach your COMPLETE code to a posting.

    best regards

    Stefan
  • timmstatimmsta Posts: 6
    edited 2009-01-07 12:15
    Hi,

    it's still the simple code i posted above. am trying things here and there but basicly it's still the same. and still i can read, but can't write. after while i would get this
    " œ4m”¶h”œ<m”¶h”œ4m”¶h”œ4m”¶h”œ4m”–h”œ<m”–h”œ4m”–h”œ4m”–h”œ4m”–h”¶h”–h”œ4m ”–h”œÚ”–h”œÚ” "
    so the complete code is above...

    thx
  • timmstatimmsta Posts: 6
    edited 2009-01-07 13:41
    Hi Everybody,

    I could solve it somehow, but still one bad thing is remaining. But First the solution (may be it might help sombody):

    the problem was a confusion in the protocol between the FullDuplexSerialPlus and processing. I solved it like this:

    void draw()
    {
    if ( myPort.available() > 0) {
    val = myPort.readString(); //reading the serial port

    String string = Integer.toString(number); //converting my integer to a string, because when processing is sending an int it wouldn't be understood

    myPort.write(string); //sending the number as a string
    myPort.write(0); //sending 0 as FullDuplexSerialPlus expects it as a termination signal (didn't look up why it works here as an int)
    myPort.write('A'); //instead of the "enter"-Signal is use a capital A as Character, otherwise things didn`t work
    delay(100);
    number++;
    }
    loop();
    }

    But still one thing remains: if i disconnect and connect again the propellor keeps sending lots of confusing signs (mentioned above). Does anybody know whats there wrong?

    cheers
  • timmstatimmsta Posts: 6
    edited 2009-01-07 13:43
    btw: the disconnecting isn't coded it's just kind of this disable thing in PST.
Sign In or Register to comment.