MCP41XXX SPI Write


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2007
    Posts
    17

    Default MCP41XXX SPI Write

    Hi.
    I cannot write a new value to a mcp41010 SPI Digital Potentiometer. What I'm trying to do is
    Code:
    WriteSPI:
        CS = 0                              ' Enable serial EEPROM
        Shiftout SI, SCK, MSBFIRST, [$06]   ' Send write enable command
        CS = 1                              ' Disable to execute command
        CS = 0                              ' Enable
        Shiftout SI, SCK, MSBFIRST, [$02, 0, 0, UpdPotVal]   ' Send address and data
        CS = 1                              ' Disable
    
        RETURN
    UpdPotVal goes from 0 to 255

    Can somebody please tell me what I am doing wrong. Here is a C code that does the same thing in case somebody knows how to make use of it!

    Code:
    #define CS PIN_B4
    #define SCLK PIN_B2
    #define SI PIN_B1
    
    set_pot (int data) {
       BYTE i;
       BYTE cmd[2];
    
       cmd[0] = data;
       cmd[1] = 0x11;
    
       output_low(SCLK);
       output_low(CS);
    
       for(i=1;i<=16;++i) {
          output_bit(SI, shift_left(cmd,2,0));
    
          output_high(SCLK);
          output_low(SCLK);
       }
       output_high(CS);
    }
    
    shutdown_pot () {
       BYTE i;
       BYTE cmd[2];
    
       cmd[0] = 0;
       cmd[1] = 0x21;
    
       output_low(SCLK);
       output_low(CS);
    
       for(i=1;i<=16;++i) {
          output_bit(SI, shift_left(cmd,2,0));
    
          output_high(SCLK);
          output_low(SCLK);
       }
       output_high(CS);
    }
    Regards

  2. #2
    Join Date
    May 2007
    Posts
    17


    Did you find this post helpful? Yes | No

    Default

    Ok. I found my problem. If anybody needs this...

    Code:
    WriteSPI:
        GOSUB GetPotVal
        CS = 0                              ' Enable
        Shiftout SI, SCK, MSBFIRST, [$11, UpdPotVal]
        CS = 1                              ' Disable
    Thanks to me

  3. #3
    Join Date
    Jan 2009
    Location
    Huntsville, AL
    Posts
    36


    Did you find this post helpful? Yes | No

    Default SPI write to MCP41010

    I know this thread is a little old, but I'm having a similar problem writing to a MCP41010. I've breadboarded it, and I know the PIC (16F628A) is working because the LED works as it should (I always put that in to make sure the chip's actually operating and running the program).

    Here's the datasheet for the MCP41010:
    http://ww1.microchip.com/downloads/e...Doc/11195c.pdf

    Here's the relevant code:
    -----------------------------------------------------
    cmcon=7
    define osc 8

    res var byte
    command var byte

    SI var porta.4 'SI
    CLK var porta.3 'CLK
    CS var porta.2 'CS
    LED var porta.1 'LED

    high porta.2
    command=19
    high LED
    pause 1000
    low LED
    pause 1000
    high LED

    repeatit:
    res=256
    low CS
    shiftout SI,CLK,1,[%00010011\8,res\8]
    HIGH CS
    pause 5000
    res=128
    low CS
    shiftout SI,CLK,1,[command,res]
    HIGH CS
    pause 5000
    goto repeatit

    end
    -----------------------------------------------------

    I've tried entering the command like both as binary and a variable to see if that has any effect, but the chip consistently reads 4.7kOhm.

    Any advice or help is appreciated!

    Dave

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Do you have a pull-up resistor on PORTA.4?

    It has an "Open collector" output, and can't go HIGH by itself.
    <br>
    DT

  5. #5
    Join Date
    Jan 2009
    Location
    Huntsville, AL
    Posts
    36


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Do you have a pull-up resistor on PORTA.4?

    It has an "Open collector" output, and can't go HIGH by itself.
    <br>
    Garsh, I think that's it. I knew there was something about one of the pins I was forgetting. I'll try that tonight and see what happens.

    So long as I use the CMCON=7 command, is porta.4 the only tricky pin I need to worry about? I also set the configuration byte to disable everything.

    Thanks!
    Dave

Similar Threads

  1. WRITE: One more PBP 2.60 Surprise ...
    By Acetronics2 in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 26th August 2009, 09:10
  2. Using SPI with External Interrupts
    By shaiqbashir in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 29th June 2008, 04:08
  3. 16-bit SPI problem
    By shaiqbashir in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th June 2008, 15:42
  4. Need the code to write to a memory
    By Hamlet in forum General
    Replies: 0
    Last Post: - 20th August 2007, 00:22
  5. Storing Strings using the Write command
    By BobP in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st November 2005, 11:31

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