SERIN confusion on receiving a string of characters.


Closed Thread
Results 1 to 23 of 23
  1. #1
    Join Date
    Feb 2013
    Posts
    1,078

    Default SERIN confusion on receiving a string of characters.

    Hello.
    I want to do the following -
    receive the data from serial port, and after code for enter is received, write next characters received into an array, and display that text on screen (8 characters total) when enter received again.

    Something like this:

    User presses enter and then types HELLO and enter again
    and my screen displays HELLO.
    If user typed in more than 8 characters before pressing the enter, just last 8 characters he entered are displayed.
    As I understand, I need SERIN for this, and it should look like this:

    Code:
    edk:
    SERIN PORTB.6,2,[13],textline[0],textline[1],textline[2],textline[3],textline[4],textline[5],textline[6],textline[7]
    pause 100
    gosub deka 'array to screen decoder
    goto edk
    I have USB2SERIAL converter TXD pin connected to PORTB.6 via 22k resistor, as PBP manual says.
    Trying to send some characters via teraterm, but get nothing written into array.
    I checked usb2serial adapter and it is working.

    What I'm doing wrong?

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: SERIN confusion on receiving a string of characters.

    Since you don't show rest of the code, only guessing I can make.

    1. Try to short tx-rx of the USB converter to make sure it is working
    2. The 22K maybe too large. Try a 4K7
    3. The array textline needs to be filled with 8 characters before serin exits. If you type less then it just waits there forever
    4. Serin will hang if the voltage input is not correct. Even if you add timeout....!
    5. Are you sure your display subroutine is OK?

    Ioannis

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: SERIN confusion on receiving a string of characters.

    What sort of USB-to-serial is this?
    The fact that you're using a 22k resistor indicates the converter is an "USB-to-RS232" converter which means you should use N9600 (Mode 6) when the RS232-signal is connected (via resistor) to the PIC. Your code, on the other hand, uses T9600 (Mode 2) indicating that the converter is "USB-to-UART" in which case the resistor isn't really needed. Also, make sure you have the GND of the converter connected to GND of PIC and - obviously - that you have selected the correct baudrate in whatever terminal program you're using.

    As usual, get the basics going first BEFORE you try to fill arrays, using wait characters, timeouts and so on.

  4. #4
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: SERIN confusion on receiving a string of characters.

    Decoder routine and other code works fine. I'll check other things too later. I already tried setting mode 6, no difference.

    The USB<>Serial converter is common one, based on CH340 chip.

    Name:  unitrode.jpg
Views: 854
Size:  138.4 KB

  5. #5
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: SERIN confusion on receiving a string of characters.

    Issue solved.
    While manual says "Pin is automatically made an input."
    In fact it does not, so I made that pin an input via TRIS register and now (mode 6) works fine.

    Now how to change above code, so it displays text immediately after pressing the enter, not waiting for 8 characters to fill in?

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: SERIN confusion on receiving a string of characters.

    Page 211 of the manual for the SERIN2 command

    Use STR ArrayVar\n{\c} where the c is the 13 (enter).

    Ioannis

  7. #7
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: SERIN confusion on receiving a string of characters.

    Like this?

    serin2 portb.6,16468,[WAIT(13),STR textline\8]

    It works, but with big delay and not repsonding to "ENTER"
    actually, it only works when 8 characters are typed in a row quickly...

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: SERIN confusion on receiving a string of characters.

    More like this

    serin2 portb.6,16468,[STR textline\8\13]

    It will exit either filling 8 characters in the textline or earlier if you hit enter

    If you want also to start filling textline after first enter then use this (not recommended though):

    serin2 portb.6,16468,[WAIT(13),STR textline\8\13]

    because serin may get confused which enter is, first or last. Better use different character for start and finish.

    Ioannis

  9. #9
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: SERIN confusion on receiving a string of characters.

    Wow thanks!
    it works like Charm!

  10. #10
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: SERIN confusion on receiving a string of characters.

    Great !

    But if you need start character better be different than stop character.

    Ioannis

  11. #11
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: SERIN confusion on receiving a string of characters.

    Tried to use this with arduino, instead of RS-232. But it does not work, since polarity is inverted.
    Added simple 1 transistor inverter and everything is fine, but maybe it is possible to modify PBP settings for SERIN2 to accept "inverted" serial data?

  12. #12
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: SERIN confusion on receiving a string of characters.

    Not sure what you mean by "arduino, instead of RS-232" but if you take a look at the SERIN2 section of the manual you'll find:
    Mode is used to specify the baud rate and operating parameters of the serial transfer.
    The low order 13 bits select the baud rate. Bit 13 selects parity or no parity. Bit 14
    selects inverted or true level
    . Bit-15 is not used.
    and
    Bit 14 selects the level of the data and flow control pins. If bit 14 = 0, the data is
    received in true form for use with RS-232 drivers. If bit14 = 1, the data is received
    inverted. This mode can be used to avoid installing RS232 drivers.
    So if 16468 works WITH external inverter then flipping bit 14 should make it work WITHOUT external inverter.

  13. #13
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: SERIN confusion on receiving a string of characters.

    Needless to say that everything regarding Serin and Serin2 is in the manual with detail.

    Cannot see connection of the above to Arduino...

    Ioannis

  14. #14
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: SERIN confusion on receiving a string of characters.

    The polarity of input signal. Not the byte or bit inversion, but voltage inversion.

    like discussed here: https://forum.arduino.cc/t/software-...class/535584/6

  15. #15
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: SERIN confusion on receiving a string of characters.

    Both are related. The RS232 protocol says that the line stays inactive at -12volt and the TTL output is at 5V at the same time. This forces you to have the appropriate inverter driver chip like MAX232 for example.

    If you do not want to use that chip then you have to make your TTL output stay at 0Volts to fool RS232 line and if you are lucky (as is the case most of the times) the other end of the RS232 line will understand that TTL output is idling.

    Hope this makes sense now.

    Ioannis

  16. #16
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: SERIN confusion on receiving a string of characters.

    I know about hardware level converters.
    I'm asking another question. Whenever is it possible for SERIN to treat input 0 as 1 and vice versa?

  17. #17
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: SERIN confusion on receiving a string of characters.

    When you flip bit 14 as Henrik clearly stated at #12

    Ioannis

  18. #18
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: SERIN confusion on receiving a string of characters.

    Yes sorry, just noticed that post
    forum is glitching too much recent days...

  19. #19
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: SERIN confusion on receiving a string of characters.

    Tried changing that bit, the result is 18516.
    Now it does not work at all....

  20. #20
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: SERIN confusion on receiving a string of characters.

    Define speed, parity, polarity.

    Ioannis

  21. #21
    Join Date
    Aug 2011
    Posts
    412


    Did you find this post helpful? Yes | No

    Default Re: SERIN confusion on receiving a string of characters.

    Quote Originally Posted by CuriousOne View Post
    Tried changing that bit, the result is 18516.
    Now it does not work at all....
    Not sure what you "flipped", but 18516 = $4854

    You had 16468 = $4054.

    bit 14 = 16384 = $4000, so flipping bit 14 should give you
    $4054 - $4000 = $0054, which is 84 dec

  22. #22
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: SERIN confusion on receiving a string of characters.

    Seems like I've flipped bit #12, not 14
    Tried your solution, it works fine, thanks!

  23. #23
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: SERIN confusion on receiving a string of characters.

    Very interesting issue, this works fine with CH340 USB to serial bridge, but does not work that well with HT42B534 USB to serial bridge - characters are received only seldomly, with long delay. This can be hardware issue or?

Similar Threads

  1. PLz Help! Serin and Serout Confusion
    By noor31 in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 16th June 2014, 19:51
  2. String of characters(array) to decimal value
    By tacbanon in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 20th June 2012, 14:30
  3. Problem receiving string
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th October 2009, 07:24
  4. Receiving Different String lengths
    By Jannie in forum Serial
    Replies: 5
    Last Post: - 26th January 2009, 05:00
  5. USART Stops Receiving Characters
    By breesy in forum Serial
    Replies: 7
    Last Post: - 26th November 2006, 03:50

Members who have read this thread : 4

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts