Need to use SPI but I'm already using the SPI port


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425

    Default Need to use SPI but I'm already using the SPI port

    I made my first project with a SPI interface (18F4550) recently but I'm never used it before this project. I need to add another component (MCP4911) but it uses SPI too. Can you make other pins SPI I/O's? The datasheet says it uses I2C but I've never used that before. Is it similar to SPI?

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


    Did you find this post helpful? Yes | No

    Default Re: Need to use SPI but I'm already using the SPI port

    Hi,
    The idea with SPI is that you can have multiple devices on the bus and then select which of them you want to communicate with by pulling that specific device chip select line low (it's always active low as far as I know).

    SPI and I2C are not compatible with each other and SPI devices and can not share bus with I2C devices. If you're using the MSSP module in the PIC (which can do SPI or I2C but not both at the same time) for the SPI chip then you're left with the software I2C commands - which can use "any" pins you like. Some PICs have two MSSP modules so you could set one up for SPI and the other for I2C.

    With that said, the datasheet for the MCP4911 seems pretty clear that it IS using SPI and not I2C, where did you get that?

    /Henrik.

  3. #3
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: Need to use SPI but I'm already using the SPI port

    With that said, the datasheet for the MCP4911 seems pretty clear that it IS using SPI and not I2C, where did you get that?
    I think I confused myself. I was looking at the MCP4011 before the MCP4911 and the MCP4011 states it uses I2C. I assumed all of the MCP identifiers use SPI but apparently that's not the case....

    SPI and I2C are not compatible with each other and SPI devices and can not share bus with I2C devices. If you're using the MSSP module in the PIC (which can do SPI or I2C but not both at the same time) for the SPI chip then you're left with the software I2C commands - which can use "any" pins you like. Some PICs have two MSSP modules so you could set one up for SPI and the other for I2C.
    So can you have all of the devices that use SPI have common SDO, CLK, SDI, etc and then each SPI module have discrete chip select lines?

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


    Did you find this post helpful? Yes | No

    Default Re: Need to use SPI but I'm already using the SPI port

    I think the only thing MCP means is Microchip (TM).
    So can you have all of the devices that use SPI have common SDO, CLK, SDI, etc and then each SPI module have discrete chip select lines?
    Yes I believe so. It's important that each of the slaves put their respective data out pin (ie. MISO or SDO) in high impedence mode when their select line goes inactive. The DAC in question (MCP4911)doesn't even have a data output pin so there's nothing to worry about there. What's the other chip you're using?

    /Henrik.

  5. #5
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: Need to use SPI but I'm already using the SPI port

    I'm using the MCP2515. I'd like to use the DAC as it will work perfect for my project. Being able to use multiple SPI devices on the same PIC is a nice feature. If using interrupts, are there other issues to consider with using the CS lines?

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


    Did you find this post helpful? Yes | No

    Default Re: Need to use SPI but I'm already using the SPI port

    Hi,
    In the case of MCP2515 and MCP4911 there really can't be any conflicts since only one of them actually puts data out on the MISO line.

    With SPI it's always the master (the PIC in this case) that initiates and "drives" the communication with the slave devices, the slave devices can not start transfering on their own. The INT\ pin on the MCP2515 - for example - is used to let the master device know that the slave needs attention. If the master is in the middle of a "converstation" with another device it's up to the master to decide if it should answer the slaves request for attention or wait (and possibly risk missing something important).

    Again, with SPI there's one master (the PIC in this case) and, at least, one slave. The master provides the clock and only the slave whos CS\ line is active (low) will listen to data being put out by the master on the SDI/MOSI line and only the slave whos CS\ line is active will (or at least should) put data out on the SDO/MISO line. A SPI slave device can never "send" anything on its own since the clock to actually shift data out on the SDO/MISO line is generated by the master.

    /Henrik.

Similar Threads

  1. 18F2520 - problem configuring fuse for port B as digital port.
    By hwhisperer in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th October 2010, 11:41
  2. LCD R/S works on Port A but not Port B
    By TDonBass in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 10th February 2009, 12:41
  3. Port A and Pot...
    By bearpawz in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 19th November 2004, 17:19
  4. Duplicating port input to port output
    By lwindridge in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 26th April 2004, 21:43
  5. Lcd And Port A
    By vicce in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 21st February 2004, 09:22

Members who have read this thread : 0

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