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


    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?

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


    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.

  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

    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?

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


    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.

  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

    Great information, Henrik. Thanks for the detailed explanation. More questions to follow soon.

  6. #6
    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

    Roadblock #1.

    I got a hold of a MCP4911E. If I understand the datasheet correctly, this chip has literally one command that is a word sized variable. I'm using the internal oscillator on a 16F690. What am I doing wrong?
    Code:
    ' ================================================================
      CS VAR PORTC.7 
     CLK VAR PORTC.1
      SDI VAR PORTC.0
      LDAC VAR PORTC.2
     
      
    '                      
    ' ================================================================
     
      
     X       VAR WORD   'GENERAL TIMER
     
    '                           PROGRAM INIT
    ' ================================================================
       
    '                            MAIN LOOP
    ' ================================================================
    CS=1
    X=0
    MAIN:
    TOGGLE PORTB.4
    
    GOSUB SEND_VOLTS
    
        
    PAUSE 100
    GOTO MAIN
    
    '                             
    ' ================================================================    
    
    SEND_VOLTS:
    TOGGLE PORTB.7
    TOGGLE PORTB.5
    TOGGLE PORTB.6
    TOGGLE PORTB.7
        LOW CS               
        LOW LDAC
        PAUSE 100
        SHIFTOUT SDI,CLK,0, [%011100111110]    
        HIGH CS             
        'HIGH LDAC
    RETURN

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

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

    Hi,
    Never used it and don't have access to one to try with.
    BUT the datasheet says that all write operations are 16 bits, 4 configuration bits followed by 12 databits where the 2 least significant bits doesn't matter for the 10-bit MCP4911. You're only sending 12 bits.
    You're using MODE 0, which accordning to the manual shifts data out LSB first while the MCP4911 expects MSB first. Doesn't really matter as long as you remember to put the bits in the correct order before sending them. SHIFTOUT does 8 bits by default, if you want anything else (up to 32) you need to specify that.

    Also, make sure you don't have any analog functions (comparator, ADC) mutliplexed onto the pins you're using. They are usually, but not always, turned on by default - always double check if you haven't already.

    I'd probably try:
    Code:
    LOW CS
    SHIFTOUT SDI, CLK, 1, [%0011010101010100\16]
    HIGH CS
    LOW LDAC
    PAUSEUS 100
    HIGH LDAC
    /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