SERIN2/SEROUT2 - first data received is always garbage


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default Re: SERIN2/SEROUT2 - first data received is always garbage

    Quote Originally Posted by Ioannis View Post
    Try this!
    Is this magic or what?

    Why did you set bit PORTB.7?

    Ioannis, you must explain why this works (please please please)
    Roger

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: SERIN2/SEROUT2 - first data received is always garbage

    Because the idle state of the serial line, for the mode you've selected, is high and you're driving the pin low when the PIC starts up. When the receiver sees that low it Thinks its the startbit and starts to shift in data which you aren't actually sending. That's the garbage you get. This happens BEFORE the execution of the SEROUT command which will THEN set it up properly for you.

    If you, in your "startup code" set the pin you're going to use as the serial out pin high and then set it to output (as Ioannis showed) then the "line" idles at the correct state and the receiver isn't "triggered" until the SEROUT command actually exectutes.

    Another (IMHO better) option is to NOT clear the TRIS bit for that particular pin.
    That way it'll remain in high impedance mode until the SEROUT command actually executes - and it will set the pin to output AND set the idle state properly based on the MODE you select.

    /Henrik.

  3. #3
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Thumbs up SERIN2/SEROUT2 - first data received is always garbage

    Thanks a lot
    Roger

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,134


    Did you find this post helpful? Yes | No

    Default Re: SERIN2/SEROUT2 - first data received is always garbage

    Quote Originally Posted by flotulopex View Post
    Ioannis, you must explain why this works
    I explained it in my first line of the post, but I guess it was a bit laconic. Henrik explained in detail.

    As always, microcontroller should be set in a known condition to avoid bizzare behaviour.

    Ioannis

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: SERIN2/SEROUT2 - first data received is always garbage

    Great illustration here of the need to have predefined states. I had been "tossing out" the first byte of data received, now I don't need to do that. Thanks guys.

    Picster

  6. #6
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: SERIN2/SEROUT2 - first data received is always garbage

    Slightly off topic, is this only true for SERIN2 / SEROUT2, and not applicable when using HSERIN / HSEROUT and the dedicated hardware /PINS on a PIC. I've always tend to use PICs with serial ports and used the excellent PIC MultiCALC tool by mister_e ( http://www.picbasic.co.uk/forum/showthread.php?t=4994 ) to give me the defines.

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,134


    Did you find this post helpful? Yes | No

    Default Re: SERIN2/SEROUT2 - first data received is always garbage

    Depends if you use it directly on RS-232 bus or with a driver which is actually an inverter.

    Bus should stay at the predefined idle state which is -12 Volts meaning that TTL logic level of the controller is at High (3 or 5 volts).

    So, the answer is yes, either Serout or Hserout.

    But if you drive directly the RS-232 bus, TTL should be reversed in the Serout2 setup and Hserout should only be used if there is a special setting in the PIC's UART that reverses the TTL state.

    Hope this is not too complicated.

    Ioannis

Similar Threads

  1. '[HD44780] Controller received data whist busy' error while simulating
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th February 2014, 09:54
  2. Replies: 2
    Last Post: - 15th December 2012, 01:19
  3. display received data
    By NURULHAIZA in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 12th May 2010, 06:03
  4. serin2/serout2
    By tazntex in forum Serial
    Replies: 14
    Last Post: - 19th September 2008, 22:01
  5. Serin2/ Serout2
    By Armadus in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 25th June 2008, 00:02

Members who have read this thread : 0

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