PDA

View Full Version : Synchronous Comms between Pics



AndyP
- 2nd December 2004, 20:06
Hi.

I am trying to establish a mini data network where there is one master PIC that sends commands to other slave Pics in my latest project, and I wanted to use asnyc comms to achieve this, mainly because of speed. The slave pics will be doing things like software PWM, but a small gap in the pulsetrain won't matter. (Its actually for an RC servo).

I don't seem to be able to achieve this with SHIFTIN and SHIFTOUT because SHIFTIN still acts in master mode whereby it provides the clock source. How have people achieved this in the past? Is it a case of "rolling your own" input routine?

Thanks,

Andy P.

AndyP
- 16th February 2005, 20:53
Finally found out that you do need to roll your own. Using bits of code that I found on here and on the old email archive, I come up with this for transmitting one byte:

TXBYTE:
FOR COUNTER = 0 TO 7
DAT_SCU = TMPBYTE.7
@ NOP
@ NOP
@ NOP
@ NOP
@ NOP
@ NOP
@ NOP
@ NOP
CLK_SCU = 1 ' Make clock go high after 8 instructions.( = 32 x 125ns = 4us wait)
@ NOP
@ NOP
@ NOP
@ NOP
@ NOP
@ NOP
@ NOP
@ NOP
CLK_SCU = 0
TMPBYTE = TMPBYTE << 1
NEXT COUNTER
RETURN

And for receiving it:

RXBYTE:
FOR Counter = 0 TO 7
WHILE CLK = 0 : WEND 'Wait for clock to go high
TMPBYTE.0 = DAT 'Assign bit value on datapin to byte variable
IF Counter < 7 Then TMPBYTE = TMPBYTE << 1
WHILE CLK = 1 : WEND 'Wait for clock to go low before re-entering loop
NEXT
RETURN