SEROUT2 and TRISIO - trash leading characters


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891

    Default SEROUT2 and TRISIO - trash leading characters

    Hello,

    This is a small code to transmit data from a PIC to another via serial RF link using LINX RF modules.

    The transmitter is powered-up only when data needs to be sent (like a simple remote control).

    After power up, there is always trash data like "UÔ*u˜" sent by the PIC before a correct message is transmitted. As long as the PIC is powered, all messages will be correct.

    I found out, to avoid this trash data, I need to comment the TRISIO statement like in the code hereunder (?!).

    But doing so, the command Led = CMCON.6 will stop working and I need a workaround like the IF..THEN commands for the Led.

    Any idea what I'm doing wrong?

    Code:
    ' Fuses  PIC12F675
    @ __CONFIG _CPD_OFF &_BODEN_OFF &_MCLRE_OFF &_PWRTE_OFF &_WDT_OFF &_XT_OSC
    
    ' Registers   76543210
    OPTION_REG = %10000000 'GPIO Pull-Ups disabled
    INTCON     = %00000000 'Set Interrupts
    ANSEL      = %00000010 'Select analog inputs
    WPU        = %00000000 'Weak pull-ups (check OPTION_REG)
    GPIO       = %00000000 'Set PORTS
        '//TRISIO     = %00000010 'Set I/Os
    CMCON      = %01000100 'Comparator Module settings
    VRCON      = %10001011 'Voltage reference
    
    ' Defines
    DEFINE OSC 4
    
    ' Variables
    D_Out   VAR GPIO.0  'Serial Data Out
    BattLvl VAR GPIO.1  'Analog Input
    Led     VAR GPIO.2  'Led is ON if battery level is low
    
    ' Program
    PAUSE 500   'Delay for VREF to settle
    MAIN:
        IF CMCON.6 = 1 THEN
            HIGH Led
          ELSE
            LOW Led
        ENDIF
        
        '//Led = CMCON.6
        
        SEROUT2 D_Out, 813,["TEST", DEC1 CMCON.6] '1200bps
        PAUSE 1000
        GOTO MAIN
    END
    Roger

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    You just need to initialize the pin to "Idle Level" at the start of the program.
    Add a ... HIGH D_Out ... statement before the ... PAUSE 500.

    You don't really need that much pause time for the initialization, but it's already in the program so you might as well use it.
    DT

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


    Did you find this post helpful? Yes | No

    Default Re: SEROUT2 and TRISIO - trash leading characters

    Thanks Darrel,

    I'll try this tonight - I'm at work now :-/

    You're right, the PAUSE is not necessary - I'll take it off.

    Can you please explain why the D_Out pin has to be set HIGH?
    Roger

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: SEROUT2 and TRISIO - trash leading characters

    The START bit of the first character begins with a transition from High to Low (with TRUE levels).

    If the pin is not in the High state, the start bit will be missed and the first data sent will be out of sync.
    It will be able to sync up after any pause in the data stream greater than 1-byte in length.

    To initialize the pin, you should set it to output, in the "Idle State" for at least 1 byte length (8.3 mS for 1200 baud).
    So just set the pin high, pause 10 mS and you should be fine.
    DT

  5. #5
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default Re: SEROUT2 and TRISIO - trash leading characters

    Hi Darrel,

    It works ;-)

    Thanks a lot.
    Roger

Similar Threads

  1. Serout2 on LCD Shows Junk Characters
    By RossWaddell in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 14th January 2013, 15:51
  2. Gpio ? Trisio ?
    By ultiblade in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 15th October 2008, 14:38
  3. Pic12f683, Trisio, High Z, A2d
    By jmbanales21485 in forum Schematics
    Replies: 9
    Last Post: - 5th July 2007, 19:34
  4. Leading 0's or BCD
    By RYTECH in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 28th December 2005, 01:06
  5. Leading/Trailing Edge
    By DelBoy in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 23rd March 2005, 12:29

Members who have read this thread : 1

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