SPI, SCK Pin set up


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Sep 2007
    Posts
    59

    Default SPI, SCK Pin set up

    I'm using a slave module on a project and so I need to tie my SCK pin on my pic (18F6520) to the other device. I was using the pin originally as a standard variable port.

    I was looking through the PicBasic Pro Compiler manual and cannot find any instructions on how to set up this pin to use as its serial clock pin.

    Can someone help me out?

    Thanks,
    Hylan

  2. #2
    Join Date
    Sep 2007
    Posts
    59


    Did you find this post helpful? Yes | No

    Default Re: SPI, SCK Pin set up

    Also, just found some info on the slave unit. It says it uses (mode 1) for clock phase and polarity. So the SCKline idles high and data is setup on the falling edge of the clock and latched on the rising edge.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: SPI, SCK Pin set up

    Hi,
    The PBP command SHIFTOUT can only work in master mode, ie the PIC is what "drives" the communications and therefor provides the clock. Is that what you're trying to do or is your external device providing the clock which the PIC is supposed to "use"?

    Many PICs have an MSSP module which is much like an USART but for syncronous type commuinications like SPI and I2C. It can operate in either master or slave mode but PBP does not have any built in commads to handle it - you'd need to drive it "manually".

    Please elaborate a bit and I'm sure someone will come to the rescue.

    /Henrik.

  4. #4
    Join Date
    Sep 2007
    Posts
    59


    Did you find this post helpful? Yes | No

    Default Re: SPI, SCK Pin set up

    Henrik,
    Yes, the pic will be the master and the other device will be the slave. I'm hoping someone has worked this out and can explain how to do this.
    Hylan.

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: SPI, SCK Pin set up

    In that case you should be able to use either the bit-banged routines (SHIFTIN/SHIFTOUT depending on which direction the data is going) or the hardware MSSP module. PBP does not have any built in commads for handling the MSSP module but it's not that hard to do "manually". Have a look at the SPIMAST.pbp example on the examples pages at MELABS.

    SHIFTIN/SHIFTOUT, being bit-banged, works on "any" pins. You just set you TRIS registers normally and make sure that comparators and ADC are turned off if they happen to be on the same pin. (Actually, PBP may handle the TRIS bit but I'm not sure.)

    /Henrik.
    Last edited by HenrikOlsson; - 25th December 2011 at 09:53.

  6. #6
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: SPI, SCK Pin set up

    I just finished getting this going for a project. You do need to set the TRIS registers. Note the data output of the master goes to the data input of the slave and vice versa, and the chip enable of the slave needs to be addressed as well. Finally you write to the SSPBUF, give it enough time for the clocking to have taken place, then read the reply from the SSPBUF. Don't forget to clear flags and interupts before moving on. My biggest pain was getting the clock edges, idles, and data positions right. After a few hours of cut and try frustration, I sat down with the timing diagrams in the datasheets and then it worked first try. When all else fails... RTFM, LOL.

Members who have read this thread : 0

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

Tags for this Thread

Posting Permissions

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