ShiftOut. Using PIC as Slave device.


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2006
    Posts
    92

    Default ShiftOut. Using PIC as Slave device.

    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

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    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?
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Apr 2006
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    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.
    Last edited by TonyA; - 13th March 2010 at 18:09.

  4. #4
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    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.

    Code:
    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
    Charles Linquist

  5. #5
    Join Date
    Apr 2006
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    Thank you for the help and advice, I appreciate it.

    Tony A

Similar Threads

  1. Watchdog Timers
    By Squibcakes in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th August 2014, 18:03
  2. Presetting Configuration Fuses (PIC Defines) into your Program
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 82
    Last Post: - 15th December 2013, 09:54
  3. Smart Star (how to use shift registers)
    By mackrackit in forum Code Examples
    Replies: 3
    Last Post: - 30th November 2008, 20:06
  4. Reading a slave USB with a pic
    By pcaccia in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 25th October 2008, 12:00
  5. I2C Master Slave issues.
    By cpayne in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 29th March 2008, 19:33

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts