PDA

View Full Version : PIC to PIC "wired" serial one-way communication - SERIN2/SEROUT2



flotulopex
- 13th April 2008, 17:53
Hello,

I'm building a IR remote control based on Bruce's information (http://www.rentron.com/Infrared_Communication.htm).

The IR link (hardware) works fine but I can't get the communication between both PICs working since I'm not familiar with the SERIN2 command.

To go on step-by-step, I don't use the IR system for the moment and "wired" both PICs together (via a 1k2 resistor).

The "emitter" PIC sends continuously this "ABCD1234efgh5678" string and this works fine. The (shortened) code in the "emitter" PIC is:
MAIN:
SEROUT2 D_Out, 49548, ["ABCD1234efgh5678", 13]
GOTO MAIN
END
The "receiver" PIC is setup to receive (:rolleyes:) the string and send it out to a Serial Terminal (currently for testing purpose).

Based on the PBP "SER2MOD" example, the "receiver" code looks like this and should make the program wait for the "A" character to be received and read the seven next characters:
' Fuses PIC12F675
@ DEVICE XT_OSC ;Xtal 4MHz
@ DEVICE WDT_OFF
@ DEVICE PWRT_OFF
@ DEVICE MCLR_OFF
@ DEVICE BOD_OFF
@ DEVICE PROTECT_OFF
@ DEVICE CPD_OFF

CMCON = %00000111 'Comparator is OFF
ANSEL = %00000000 'Disable analog inputs
OPTION_REG = %10000000 'GPIO Pull-Ups disabled
INTCON = %00000000 'All Interrupts disabled
GPIO = %00000000 'Ports Levels
TRISIO = %00001000 'Ports Directions

D_Out VAR GPIO.2 'Serial Data Out
D_In VAR GPIO.3 'Serial Data In
D_Data VAR byte[8]'Serial Data

MAIN:
SERIN2 D_In, 49548, [WAIT("A"), STR D_Data\7]
SEROUT2 D_Out, 49548,[STR D_Data\7, 13, 10]
GOTO MAIN
END
Problem: it seems I don't get anything into the receiver PIC or at least, this is what I feel since the Serial Terminal stays blank.

NB: 49548 is the data mode: 2400bauds, Open, Inverted, No Parity.

Darrel Taylor
- 13th April 2008, 22:44
Hi Roger,

Do you have a Pull-Up resistor on the serial line?

SEROUT2 mode 49548 is Open Collector output. It never drives the line high, so it requires a pull-up.
From your description, it sounds like you just have a 1.2k in series.

Alternatively, you can use mode 16780 which will drive it high.
<br>

mister_e
- 13th April 2008, 22:49
Sounds right... not sure how and why SERIN2 deal with it... how on earth an input could be an open-collector type ;) NO i haven't open the LIB(s)

Darrel Taylor
- 13th April 2008, 22:57
As far as SERIN2 is concerned, it doesn't matter.
49548 and 16780 are the same thing.

But it will make a difference with the SEROUT2.
49548 - open collector output.
16780 - Driven output.
<br.

flotulopex
- 14th April 2008, 07:03
...Do you have a Pull-Up resistor on the serial line?
<br>
Yes, a 10k. The 1k2 resistor is connected between both PICs.

I'll have a try with a driven output.

flotulopex
- 14th April 2008, 20:02
Looking around the Internet for some additional information about IR transmission, I found out that i.e. SONY uses a Pulse Width Modulation protocol that looks simple to implement with PICs (http://www.sbprojects.com/knowledge/ir/sirc.htm).

So instead of trying to establish a "serial" communication, I'll have a go with PULSOUT/PULSIN.

Might be easier since the IR (hardware) layer is already working well.