Shiftout/in


Closed Thread
Results 1 to 6 of 6

Thread: Shiftout/in

  1. #1
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116

    Cool Shiftout/in

    I used to send data between 2 cards using serout, but after fitting feedthru caps to help with EMC tests this no longer works, even if I goto 300 baud.
    So I have tried to write a slave shiftin routine, which i think should be included in pbp, but anyway I am not having any joy at all. Has anyone rolled their own shiftin routine? I am trying to send/receive word variables at a very slow rate. I have looked at spislave.bas but I dont understand it at all. I wish the pbp manual was complete, there seems to be more missing than is included.

    Regards Bob...
    Last edited by BobEdge; - 22nd August 2007 at 11:58.

  2. #2
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by BobEdge View Post
    I used to send data between 2 cards using serout, but after fitting feedthru caps to help with EMC tests this no longer works, even if I goto 300 baud.
    Do you mean you have feedthrough caps in the actual serial line ?

    If so then there is no DC path and the receiving PIC will only see short duration spikes not proper logic levels needed to send data.
    Keith

    www.diyha.co.uk
    www.kat5.tv

  3. #3
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116


    Did you find this post helpful? Yes | No

    Default

    yes the feedthru caps are in the serial line. But they do have a dc path. Here is a link to them on the Farnell website.
    http://uk.farnell.com/jsp/Passive+Co...questid=248319

  4. #4
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by BobEdge View Post
    yes the feedthru caps are in the serial line. But they do have a dc path. Here is a link to them on the Farnell website.
    http://uk.farnell.com/jsp/Passive+Co...questid=248319
    OK.

    Was just a thought ..... a wrong thought !
    Keith

    www.diyha.co.uk
    www.kat5.tv

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    If you need total control of data & clock timing, it should be relatively easy to roll your own
    synchronous serial routines.

    See if something like this works. To adjust data & clock timing just change the constant
    delays or even switch to PAUSEUS VS PAUSE.
    Code:
    DEFINE OSC 4            ' 16F877A @ 4MHz sending
    DEFINE LOADER_USED 1
    
    SYMBOL DOUT = PORTB.0   ' data output pin
    SYMBOL CLOCK = PORTB.1  ' clock output pin
    
    DAT_DLY CON 1           ' data bit rate = DAT_DLY*2 + CLK_DLY + loop overhead
    CLK_DLY CON 1           ' clock time
    
    PACKET VAR WORD         ' 16-bit data packet
    INDEX VAR BYTE          ' data packet bit index pointer/loop counter
    
    PORTB = 0               ' pins idle low
    TRISB = %11111100       ' RB0, RB1 outputs
    PAUSE 3000
    
    MAIN:
        PACKET = %1010101010101101  ' load 16-bit data packet (receiving PIC displays $AAAD)
        
        ' delay values give around 3.1mS wide data bits with a 1mS clock pulse
        ' in the center of each data bit. 
    SEND:
        FOR INDEX = 15 TO 0 STEP-1  ' send msb first  (lsb first would be 0 to 15)
            DOUT = PACKET.0[INDEX]  ' place data bit on RB0
            PAUSE DAT_DLY           ' pause bit time
            HIGH CLOCK              ' set clock in middle of data bit
            PAUSE CLK_DLY           ' pause for clock time
            LOW CLOCK               ' low clock
            PAUSE DAT_DLY           ' pause for last of data bit
        NEXT INDEX                  ' get next data bit
        LOW DOUT                    ' data out & clock pins idle low
        PAUSE 50
        GOTO MAIN
        END
    You may want to work out some type of synchronization between the two. I flipped on
    power to the receiving end just before the transmitter to synch-up.
    Code:
    DEFINE OSC 20           ' 18F2431 @ 20MHz receiving
    DEFINE LOADER_USED 1
    
    SYMBOL DIN = PORTB.0    ' data input pin
    SYMBOL CLOCK = PORTB.1  ' clock output pin
    
    IDLE CON 0              ' idle logic state
    ACTIVE CON 1            ' active clock logic state
    
    PACKET VAR WORD         ' 16-bit data packet
    INDEX VAR BYTE          ' data packet bit index pointer/loop counter
    
    TRISB = %11111111       ' data and clock both inputs
    PAUSE 3000
    
    MAIN:
        PACKET = 0          ' clear data packet
        
    RCV:
        FOR INDEX = 15 TO 0 STEP-1  ' receive msb first
            WHILE CLOCK = IDLE      ' wait for active clock
            WEND
            PACKET.0[INDEX]=DIN     ' place data bit on RB0 in packet
            WHILE CLOCK = ACTIVE    ' wait for clock to return to idle state
            WEND
        NEXT INDEX                  ' get next data bit
        HSEROUT [HEX4 PACKET,13,10] ' show value received
        GOTO MAIN
        END
    You could probably use SHIFTOUT and SHIFTIN too, but if you need full control of data and
    clock rates, something like this should give you the extra flexibility.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116


    Did you find this post helpful? Yes | No

    Default

    Thanks very much Bruce that worked a treat. Now if I can just get the chip to send the data to the DAC im in busyness.

    Regards
    Bob...

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