Debug/Serout/Serout2 - please, need advice ...


Closed Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    578

    Default Debug/Serout/Serout2 - please, need advice ...

    Hi !
    I try to understand how work communication between PIC and PC.
    I wrote this simple code :
    Code:
    @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON 
     
    INCLUDE "modedefs.bas"       
    DEFINE OSC 04                 
            CMCON = 7               
            VRCON = 0               
            WPU = 0                 'no wake pullup
            IOCB = 0                'no int. on change
            ANSEL = %01010001       
            ADCON0 = %10000001      'right just , Vref=Vdd , ch.0 , A/D on
            GPIO = %00101001        'preset I/O
            TRISIO = %00001001      'configure direction  1=input 0=output
            OPTION_REG = %10000111
    
    advalue        var     word
    
    Main:
    PauseUs 50                  'sample time
            ADCON0.1 = 1                'start A/D
            @ nop
            while ADCON0.1 = 1          
            wend
            advalue.byte1 = ADRESH         'get A/D value
            advalue.byte0 = ADRESL
    
            if advalue < 650 then
               SerOut2 GPIO.5,300,["Advalue : ",DEC advalue, 13, 10]   ; the calculated result is "93" , but ?!
            endif
    goto Main
    I use on GPIO.0 one 1k resistor to +5 volts and one 100R resistor to ground. Advalue is 93, don't ?!

    But on RealTerm I am unable to see the "real" value of Advalue, no matter what option I choose...
    What I do wrong ?!
    Thanks in advance !
    Attached Images Attached Images  

  2. #2
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: Debug/Serout/Serout2 - please, need advice ...

    Hi Fratello.

    You don't say how your PIC is connected to the PC.
    Whether you have the PIC connected via a MAX232 chip or direct to the PC.
    e.g.
    PIC -> MAX232 -> PC
    or
    PIC -> PC

    It makes a difference on how you use SEROUT or SEROUT2.

    Also, take a look in the PBP manual for the SEROUT2 command.
    I don't think your MODE setting is quite right for you comms settings on the PC, not to mention what I said above about the connectivity between the PIC and the PC.
    If you are trying to use 300 baud 8N1 then setting MODE 300 is most likely not correct.

    Read through section 5.73 (SEROUT2 command) and then look at the table in section 8.6 (SERIN2/SEROUT2 Mode List).

    With this I think you can find the correct MODE value.

    A couple of more suggestions.
    1. You have DEFINE OSC 04
    I don't know if this is an issue since no errors are reported during compile, but you may want to use DEFINE OSC 4 instead as per the manual.
    2. Try a simple program that you just send out a known text string and maybe a value via the serial port without the ADC stuff.
    See if you can get just that to work with your PC and then move on to the ADC stuff.

    Just some suggestions.
    Last edited by Tabsoft; - 14th May 2015 at 19:55.
    Regards,
    TABSoft

  3. #3
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    578


    Did you find this post helpful? Yes | No

    Default Re: Debug/Serout/Serout2 - please, need advice ...

    Thanks for reply !
    I use simple link PIC to PC (GPIO.5 connected to DB9 - pin 2).
    I tried DEBUG command too ... with same results ...
    Of course I added in my program :
    Code:
     DEFINE DEBUG_REG GPIO          'Set Debugin pin por
     DEFINE DEBUG_BIT 5             'Set Debug pin bit
     DEFINE DEBUG_BAUD 2400         'Set Debug baud rate
     DEFINE DEBUG_MODE 0            'Set Debug mode: 0=true,1=inverted
    My schematic is based on Mr.GioppY "serial voltmeter" (http://www.picbasic.co.uk/forum/showthread.php?t=7182) with modification for my purpose ...
    Mr.GioppY use, in his program :
    Code:
    debug  dec TmpW dig 4,dec TmpW dig 3,",",dec TmpW dig 2,Cr,Lf
    but with VB program.
    First I tried "Debug DEC Advalue, 13, 10" , but I have same results in RealTerm.
    Attached Images Attached Images  

  4. #4
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Debug/Serout/Serout2 - please, need advice ...

    for 2400 baud try mode 16780 for inverted data.
    Like Tabsoft suggested, you don’t have a real RS232 serial port there.

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


    Did you find this post helpful? Yes | No

    Default Re: Debug/Serout/Serout2 - please, need advice ...

    SEROUT2 GPIO.5,19697,[ "Hello World !!! ",$D ,$A]

    Try the above for 300 baud without a MAX232 chip.
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Debug/Serout/Serout2 - please, need advice ...

    And if that doesn’t work, just get the chip to tell you what it is

    Code:
    mode var word
    mode = 100;
    WHILE mode < 60000
    SEROUT2 GPIO.5,mode,[ "     ",DEC mode,"     ", $0D, $0A]
    mode = mode + 1;
    WEND

  7. #7
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Debug/Serout/Serout2 - please, need advice ...

    Interesting project.

    I'm no expert on schematics, but something doesn't sit right with the coms section. The 5v logic is used to turn on the 2n3906 via a 4k7 current limiting resistor. To prevent a direct short R10 is used, with R8 restricting the current drawn through the transistor. Normal RS232 ports like to use 12v not 5v as shown, so wondered if this could be part of the problem. But then in the linked post it must of worked for the OP who designed the volt meter ?? uhmm.

    Just for clarity, I would get an FTDI based 5v USB to Serial TTL converter, that is seen as a normal com port by the PC and see if that works... If so then the com1 port on the PC is not getting a true voltage and corrupting the system. In the original schematic there is a 20v max line. If this was 12v and the emitter of the transistor was connected to this line than that might work as it's closer to the normal RS232 voltage levels, but then again - I'm no expert and wouldn't want you to damage the PC.

    One other thing you can try - check the com setting in the serial capture program and set the flow control to none... I found that with this set to any other option in many serial terminal programs you get garbage displayed on the screen.

    Disclaimer: you follow any suggestions at your own risk.

  8. #8
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    578


    Did you find this post helpful? Yes | No

    Default Re: Debug/Serout/Serout2 - please, need advice ...

    Thanks for support !
    The schematic is "valid" since with the original soft works just fine ... When I "give up" to voltage monitor program (VB) I am unable to receive consistent data.

  9. #9
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Debug/Serout/Serout2 - please, need advice ...

    Hey, wasn't being negative....like I stated - I'm no expert... if it works with the original code then the hardware is fine....

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


    Did you find this post helpful? Yes | No

    Default Re: Debug/Serout/Serout2 - please, need advice ...

    You screen shot shows 300 baud, that is why I gave the example that I did.

    Now I notice you code a schematic showing 2400 baud.....
    Dave
    Always wear safety glasses while programming.

  11. #11
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Debug/Serout/Serout2 - please, need advice ...

    RS232 is -12 Volts on the low, so there’s actually 24 Volt difference between one state and another.
    I don’t believe it’s possible to do RS232 with any one single transistor if the ground is connected to the other device.

    The whole compromise to make 5 Volt RS232 ports is just that.
    It could be damaging to connect a real RS232 port to a pic without proper clamping if it didn’t have some awesome IO characteristics.

  12. #12
    Join Date
    Aug 2011
    Posts
    408


    Did you find this post helpful? Yes | No

    Default Re: Debug/Serout/Serout2 - please, need advice ...

    The RS232 voltage spec:
    -3V to -25V = logic 1
    +3V to +25V = logic 0


    However, if you take a look at a lot of the "MAX232" class chips you'll find that the RXD receiver input has the following characteristics:
    Input high threshold: 1.7V (typ), 2.4V (max)
    Input low threshold: 0.8V (min), 1.8V (typ)
    Input resistance: 3K-7K ohms (pull-down to ground)

    Those levels are actually close to what you'd get out of most TTL outputs! It's not "RS232", but you can pretty much drive that directly from a PIC output pin.
    I wouldn't do it for a real commercial product, but for a one-of you could probably get away with it.

    Connecting to the TXD level from an RS232 output is a different story. There you have to deal with the fact that you might get as much as +/-25V levels on the pin.

  13. #13
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Debug/Serout/Serout2 - please, need advice ...

    Folks don't get distracted by the schematic. This can work with that schematic, or with a piece of wire from pin 2 of the PIC to pin 2 of the DB-9. The transistor and it's support resistors are not really helping anything, but not really hurting either. The problem will be in the code, or possibly a bad PIC. I remember 12 bit cores don't like SEROUT2 but I'm not sure if this device is one of these?

  14. #14
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    578


    Did you find this post helpful? Yes | No

    Default Re: Debug/Serout/Serout2 - please, need advice ...

    Thanks for support !
    As I say the schematic is fine (I think !) : http://www.picbasic.co.uk/forum/showthread.php?t=7182
    Just my program is bad ...

Similar Threads

  1. 12f629 serout,debug and serout2 timings
    By Dennis in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 10th January 2010, 04:13
  2. Serout/serin issues, advice required
    By Agent36 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 29th May 2008, 23:51
  3. debug vs serout vs serout2
    By mychangl in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th March 2007, 06:35
  4. Serout/serout2
    By fowardbias in forum Serial
    Replies: 10
    Last Post: - 23rd January 2006, 06:48
  5. Debug vs SerOut Commands
    By EShatara in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 29th November 2004, 06:16

Members who have read this thread : 2

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