Serin,Serout Problem


+ Reply to Thread
Results 1 to 16 of 16
  1. #1
    Join Date
    Oct 2012
    Posts
    4

    Default Serin,Serout Problem

    Hello!

    I am a Newbie on programming Micros.
    I have a PIC 16F84 an wrote a littele Program.
    This is my Programm:
    INCLUDE "modedefs.bas"
    B0 var byte
    a var byte
    SI var PORTB.7
    start:
    SERIN si,T2400,B0
    if b0 <> "0" then
    for a= 0 to 255
    serout si,T2400,[a]
    next a
    endif
    goto start
    end

    When i send an X in the serial communicator window,the PIC sould send
    the complette ASCII codes.
    But the PIC send this:
    X!A9#T̑!3H!CR"ʒ*Sq҉f2cRbr j(PPb=RiQQfy}-RR**-Mm*
    Xq-1=AMQ]amq}*``
    !"#,-./0123<=>[email protected]\]^_`abclmnopqrs|}~ *

    The Settings of then Serial Communicator is:
    COM1
    2400 Baud
    NoParity
    ByteSice 8
    1 Stop Bit

    What do i wrong?
    I think its a little Problem for the most afl here.
    Sorry for mx English(german)

    Thanks a lot for your help!

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default Re: Serin,Serout Problem

    Welcome to the forum.

    Try Inverted mode.

    From the manual
    While single-chip RS-232 level converters are common and inexpensive, the excellent I/O specifications of the PICmicro allow most applications to run without level converters. Rather, inverted input (N300..N9600) can be used is conjunction with a current limiting resistor.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Dec 2010
    Posts
    400

    Default Re: Serin,Serout Problem

    Lots of possible error sources, including, most likely, clock configuration. Please post your complete code.
    Are you using something like a MAX232 device? If not, you need to invert your data.

  4. #4
    Join Date
    Oct 2012
    Posts
    4

    Default Re: Serin,Serout Problem

    Quote Originally Posted by Charlie View Post
    Are you using something like a MAX232 device? If not, you need to invert your data.
    I'm having a similar problem with my project and I was told to ensure the data sent was true (not inverted). I am using a 16f88, not an 84 maybe that's the difference?

  5. #5
    Join Date
    Dec 2010
    Posts
    400

    Default Re: Serin,Serout Problem

    Quote Originally Posted by harralk View Post
    I'm having a similar problem with my project and I was told to ensure the data sent was true (not inverted). I am using a 16f88, not an 84 maybe that's the difference?
    Why don't you simply try it? It's a grand total of 1 character difference in 2 places in the posted code... Certainly no need to take our word for it

  6. #6
    Join Date
    Feb 2011
    Location
    Michigan, USA
    Posts
    33

    Default Re: Serin,Serout Problem

    Serial out and serial in on same PIC pin? Normally separate pins.

  7. #7
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,817

    Default Re: Serin,Serout Problem

    Quote Originally Posted by orwell101 View Post
    Hello!

    I am a Newbie on programming Micros.
    I have a PIC 16F84 an wrote a littele Program.
    This is my Programm:
    INCLUDE "modedefs.bas"
    B0 var byte
    a var byte
    SI var PORTB.7
    start:
    SERIN si,T2400,B0
    if b0 <> "0" then
    for a= 0 to 255
    serout si,T2400,[a]
    next a
    endif
    goto start
    end

    When i send an X in the serial communicator window,the PIC sould send
    the complette ASCII codes.
    But the PIC send this:
    X!–ˆA9Œ#‘T‘!†Ž3’H!CR‰"’*Sq‰fœ2cRbr‚’ j(PPb=RiQQfy}-RR**™-Mm*
    –Xq-1=AMQ]amq}‘*˜``
    !"#,-./0123<=>[email protected]\]^_`abclmnopqrs|}~€‚ƒŒŽ‘’“œžŸ *

    The Settings of then Serial Communicator is:
    COM1
    2400 Baud
    NoParity
    ByteSice 8
    1 Stop Bit

    What do i wrong?
    I think its a little Problem for the most afl here.
    Sorry for mx English(german)

    Thanks a lot for your help!
    That you get output is good, that it is garbage can have several causes. 1 oscillator is not defined in code, 2. baud rate mismatch between sender & receiver. 3. sending and receiving mismatch (one true the other inverted). 4. long or loss-ey cables causing data corruption, or receiving noise.5.mismatched data profile I E parity # of bits . . .
    I would DEFINE OSC x where x represents your crystal or resonator, or if you are using INTRC then make (x) 4. The define does not make the oscillator work at that speed it simply forces PBP to adjust all of it's timing to accommodate the defines speed.
    Last edited by Archangel; - 28th October 2012 at 08:19.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  8. #8
    Join Date
    Oct 2012
    Posts
    4

    Default Re: Serin,Serout Problem

    Hello!
    I have used DEFINE OSC 4
    and N9600.
    I think the Problem is my COM Settings.
    What shoul i use there?

  9. #9
    Join Date
    Oct 2012
    Posts
    9

    Default Re: Serin,Serout Problem

    I know how frustrating it can be to get this problem. It cost me several hours (and a dead USB to RS232 dongle) to isolate my problem. It turns out the internal oscillator (4Mhz) on my 12F629 was too far off. I probably killed the internal calibration value by mistake at some other time.


    "for a= 0 to 255"

    You are getting some data in acceding order. Using printable characters can help by counting the number of correct ascending order before it breaks consistent order. The control characters can be muddying up things. Maybe:

    for a=32 to 126 'send only printable characters

    Also, characters pacing might help

    DEFINE CHAR_PACING 1000 'character pacing of 1ms

    My Hyper Terminal setting is on ASCII (chosen from a list in the setup)

  10. #10
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default Re: Serin,Serout Problem

    In your code, change back to 2400
    N2400

    And leave the PC program at 2400.

    Let us know what happens so we can help more if needed.
    Dave
    Always wear safety glasses while programming.

  11. #11
    Join Date
    Oct 2012
    Posts
    4

    Default Re: Serin,Serout Problem

    Hello!
    I have tried this.
    INCLUDE "modedefs.bas"
    B0 var byte
    define OSC 4
    DEFINE CHAR_PACING 1000
    A var byte
    SI var PORTB.7
    start:
    SERIN si,N2400,B0
    if b0 <> "0" then
    for a= 32 to 126
    serout si,N2400,[a]
    next a
    endif
    goto start
    end

    And the PIC sends nothing more

  12. #12
    Join Date
    Oct 2012
    Posts
    9

    Default Re: Serin,Serout Problem

    It stops sending anything? Or the same garbage? Which?

    And I'm with Mike:

    "Serial out and serial in on same PIC pin? Normally separate pins. "
    Last edited by norohs; - 30th October 2012 at 15:59.

  13. #13
    Join Date
    Oct 2012
    Posts
    4

    Default Re: Serin,Serout Problem

    Hello!
    I think i must send the CHR$ code of a.
    How can i do this?

  14. #14
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default Re: Serin,Serout Problem

    About half way down is the Standard ASCII Character Set
    http://melabs.com/resources/ascii.htm
    Dave
    Always wear safety glasses while programming.

  15. #15
    Join Date
    Oct 2012
    Posts
    9

    Default Re: Serin,Serout Problem

    Quote Originally Posted by orwell101 View Post
    Hello!
    I think i must send the CHR$ code of a.
    How can i do this?
    I don't think so. By limiting the decimal value of 'a' to printable characters, the byte being sent will print that ASCII character. So, the way its being sent now is '32' will print a space, '33' will print "!",,,, '65' will print "A", etc..

    Are you willing to try separate and different ports for the SERIN and SEROUT? Sending and receiving on the same port pin is something I've never seen done using SERIN and SEROUT... and I have never considered doing it myself. It sure would eliminate one obvious anomaly.

    <snip...>
    SI var PORTB.7
    start:
    SERIN si,N2400,B0 <===== SERIN (on) PORTB.7
    if b0 <> "0" then
    for a= 32 to 126
    serout si,N2400,[a] <====== serout (on) PORTB.7

    Try not using the same port for SERIN and SEROUT.

    It may not be an issue for PBP to use the same port pin, but I can't imagine what the hookup to the RS232 would look like.

    EDIT: To be simple about it, just remark out:

    start:
    ' SERIN si,N2400,B0
    ' if b0 <> "0" then

    for a= 32 to 126
    serout si,N2400,[a]
    next a
    ' endif
    goto start
    Last edited by norohs; - 31st October 2012 at 05:33.

  16. #16
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305

    Default Re: Serin,Serout Problem

    If that doesn't work try

    start:
    ' SERIN si,N2400,B0
    ' if b0 <> "0" then
    for a= 32 to 126
    serout si,T2400,[a]
    next a
    ' endif
    goto start

    I believe if the issue is only with inverted data that should get it to display.

Similar Threads

  1. Serin and Serout problem
    By rubisharmax in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 10th June 2012, 14:20
  2. problem with serout and serin 2
    By amtechnology in forum General
    Replies: 0
    Last Post: - 14th May 2012, 14:08
  3. Another Serin/Serout Problem!
    By jmbanales21485 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 7th June 2007, 17:26
  4. Serin serout problem
    By lerameur in forum mel PIC BASIC Pro
    Replies: 336
    Last Post: - 6th February 2007, 05:25
  5. serout and serin problem
    By nicolelawsc in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th April 2006, 20:44

Posting Permissions

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