PDA

View Full Version : SEROUT2 and TRISIO - trash leading characters



flotulopex
- 2nd April 2013, 22:38
Hello,

This is a small code to transmit data from a PIC to another via serial RF link using LINX RF modules (https://www.linxtechnologies.com/en/products/modules/lr-rf-transmitter-receiver).

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?


' 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

Darrel Taylor
- 3rd April 2013, 01:02
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.

flotulopex
- 3rd April 2013, 10:08
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?

Darrel Taylor
- 3rd April 2013, 15:02
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.

flotulopex
- 3rd April 2013, 18:48
Hi Darrel,

It works ;-)

Thanks a lot.