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

    Awesome! I found the answer I was looking for. It was located in this post: http://www.picbasic.co.uk/forum/show...6874#post16874

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


    Did you find this post helpful? Yes | No

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

    Hi,
    I'm glad you've got it working. I don't understand the reference to "an extra bit" but perhaps it doesn't matter now that it works. I see that you have 17 bits in your SHIFTOUT command but you're actually only sending 16.

    For reference, this is the datasheet I'm looking at. Section 5.2 explains how the write command works, ie 4 config bits and 12 databits for a total of 16bits. The transfer from the input shift register to the actual device will occur only if 16bits has been shifted in, you can't do less or it will be ignored.

    If LDAC is low the output voltage will be updated at the rising edge of CS. If LDAC is high at the rising edge of CS the output will be updated at the falling edge of LDAC. This allows multiple DACs to be connected to the SPI bus and writen one after the other and then, with their LDAC pins connected together, their outputs gets updated simultanously instead of one by one as they are written to by the SPI bus.

    On the next page, register 5.2 shows the write command register for the MCP4911 and what each of the config bits do. Again, no "extra bit" as far as I can see.

    You can't just write the 10 databits to the device, you must transfer all 16 bits including the config bits - even if they don't actually change. If you don't transfer 16bits the transfer will be ignored as explained in section 5.2.

    Here's something you could do to make it more clear what's happening.
    Code:
    OutWord VAR WORD
    
    WRITE_DAC CON 0
    Vref_BUF CON 16384
    Vref_UnBuf CON 0
    GAIN_1x CON 8192
    GAIN_2x CON 0
    VOut_ON CON 4096
    VOut_OFF CON 0
    
    OutWord = WRITE_DAC + VRef_UnBuf + GAIN_1x + VOut_ON + 456   ' Where 456 is your analog value.
    
    SHIFTOUT SDI, CLK, 1, [OutWord\16]
    The above would then shiftout the value 12744, which in binary is 0011000111001000.

    /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