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
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?
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.
Re: SEROUT2 and TRISIO - trash leading characters
Hi Darrel,
It works ;-)
Thanks a lot.