Announcement

Collapse
No announcement yet.

Simple Serial Communication

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Simple Serial Communication

    Hi

    I am attempting to communicate with a simple gauging interface device through RS232 comms.


    I know that if I send '1<CR>' out to the device it will respond with '1: +####.### mm'. I have used this device, and many other RS232 devices over the years communicating with PLCs but here I have fallen flat on my face at the first hurdle.

    I have connected uLCD-35DT to a PC serial port and then run Termite (terminal emulator) on the PC. When I send just the number '1' depending on various settings I get varying results but never a '1'!

    After struggling for a long while I tried something else, now I have just this:

    var char;

    repeat
    char := serin();
    if (char >= 0)
    print(char, "\n");
    endif

    forever

    when this is running and I start Terminal from within Workshop, and then send just the number '1' the screen displays '255'. Press '1' again and I might get another '255' but it could be '254' or '252'.

    I assume that 'Terminal' is communicating through the programming lead into COM0 and that reassures me the problem is not my wiring, connections or settings when trying to use COM1 because the result is the same.

    I feel like an idiot for not being able to work this out but what's going on?


    Andy




  • #2
    Are both devices set to the same baud rate?

    If they were and you typed a 1 the display would show 49, that is because the character 1 is hex 0x31 which is decimal 49.

    If you wanted to display a 1
    print([CHR] char,"\n") ;
    would do the job.
    Mark

    Comment


    • #3
      Yes the baud rate is set the same when I connect to the PC, I checked this many times. However when I just added com_SetBaud(COM0, 960) to the above and run Terminal at 9600 it works fine.

      I will go look very closely at my setup.

      Thank you Mark

      Andy

      Comment


      • #4
        I can't see any incorrect settings.

        My code for communicating with the PC is:

        var buffer1[100];
        var read1;
        var state, n, x, y;
        var ptr;
        var ch;
        var char;
        var test[8];


        func main()


        COM1_RX_pin(PA5);
        COM1_TX_pin(PA4);
        com_Mode(8, 'N', 1, COM1);
        com_SetBaud(COM1, 960);
        com1_Init(buffer1, 11, 0);


        gfx_Cls();

        touch_Set(TOUCH_ENABLE); // enable the touch screen

        repeat
        state := touch_Get(TOUCH_STATUS); // get touchscreen status
        n := img_Touched(hndl,-1) ;

        //-------------------------------------------------------------
        if(state == TOUCH_PRESSED) // if there's a press
        x := touch_Get(TOUCH_GETX);
        y := touch_Get(TOUCH_GETY);
        getreadings();
        endif

        //-------------------------------------------------------------
        if(state == TOUCH_RELEASED) // if there's a release
        endif

        //-------------------------------------------------------------
        if(state == TOUCH_MOVING) // if it's moving
        x := touch_Get(TOUCH_GETX);
        y := touch_Get(TOUCH_GETY);

        endif


        forever

        endfunc


        func getreadings()

        ch := 0x31;
        to(COM1); print(ch);

        pause(1000);
        read1 := serin1();
        print("Depth = ", serin1(), "\n");

        endfunc


        The terminal emulator on the PC is set the same as above, I even had other people look to see if they can see a difference.

        Andy

        Comment


        • #5
          Click image for larger version

Name:	20150618_132053.jpg
Views:	133
Size:	2.12 MB
ID:	45912


          This is the result from the above code. The result is consistent, over and over the '1' results in 'g'.

          Attached Files

          Comment


          • #6
            As I mentioned earlier the print, as you have it will send the number 49 (0x34, 0x39) to the terminal program.

            That's also what I get with your code.

            Which raises the next question, just how are these two points physically connected?

            The display is 'standard' TTL, it works with either 3v3 or 5v

            Mark

            Comment


            • #7
              currently I have PA4 and 5 set up as RX and TX COM1 and these are linked directly to pins 2 and 3 on the back of the PC COM1. I had not considered the voltage, I expected it to be a standard and with my results being consistent I disregarded noise etc.


              Andy

              Comment


              • #8
                The display modules have a TTL level Serial UART, not an RS232 port.

                RS232 and TTL UART is totally different voltage levels.

                I just googled for a website for a comparison for you, and this Sparkfun tutorial came up.
                https://www.sparkfun.com/tutorials/215

                I hope that is of some help

                Regards
                James

                Comment


                • #9
                  Ok thank you, definitely going to be the problem I think. Something for me to do Monday morning

                  Thank you for your help. have a nice weekend.

                  Andy

                  Comment

                  Working...
                  X