PDA

View Full Version : ShiftOut. Using PIC as Slave device.



TonyA
- 12th March 2010, 23:18
Hi,

I not sure if this is possible, since I am confused about shiftout command.

I would like to use the pic as a slave device. The pic would receive the clock signal from a master device, and the pic would shift out a byte.

The master device sends the latch and clock data, the pic would receive that data and shift out a byte of serial data. Is this possible?

Thanks for any help.
TonyA

mackrackit
- 13th March 2010, 16:39
I am not sure either... Never used the PIC as a slave.

If the master device could send a signal to the PIC letting the PIC know data is ready then maybe the PIC could start a SHIFTIN ?

What is the master device?

TonyA
- 13th March 2010, 18:03
Thanks. Well my problem is that I might not fully understand the shiftout command.

The master is another microcontroller, the Atmega8. The Atmega is sending a clock signal and latch data, the pic (slave device) will receive the clock signal and latch data, and then send out a byte of data to the Atmega.

So I'm guessing that I would just connect the clock output of the master (Atmega) to an input pin of the pic (slave) and that would be the clockpin of the command: shiftout dataOutpin, clockpin, (serial data)

The latch output signal of the master (Atmega) would be received by an input pin of the pic (latchReceivePin), and I guess I would do something like this?

If latchReceivePin = 1 then 'if the pic receives a "high" signal on its input pin then shift out a byte of data to the Atmega.
shiftout, etc.

I still don't know if I understand "shiftout" correctly, but I'll experiment with this today. If anyone can offer any advice or clues please let me know.

Thanks again.

Charles Linquis
- 13th March 2010, 18:11
Something like this should work (untested). Note that is "blocking", and that the code will not advance past this until you get 8 high-to-low transitions on the clock.



GetNextByte:

BitCounter = 0
GetNextBit:
While ClockPin=1:Wend ; Sits here and does nothing while clock pin is high
DataByt.0 = DataPin ; Samples data pin as soon as clock goes low
BitCounter = BitCounter + 1 ; Keeps track of number of bits received
If BitCounter = 8 then goto GotByte ; When we have a byte, get out
DataByt = DataByt << 1 ; Move things over for next bit
WHILE ClockPin=0:WEND ; Sit here while clock is low
Goto GetNextBit ; Grab next bit if we haven't got all 8

GotByte:
...
...
...
END

TonyA
- 16th March 2010, 19:10
Thank you for the help and advice, I appreciate it.

Tony A