Loading...
Pages: [1]   Go Down
Author Topic: mcp42010 digipot SPI connection  (Read 444 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everyone...
i'm trying to make a mcp42010 digipot (http://www.datasheet4u.net/download.php?id=440013) work using a SPI protocol, but nothing works.
i'm using an arduino nano, i have tried using a very slightly modified version of the example digipot sketch, and i have checked the pins and the connections many times, but the digipot doesn't seem to receive any information, and just lights the led very dimly.
i have tried swapping the IC but nothing changes.

the program i'm using
Quote

// inslude the SPI library:
#include <SPI.h>


// set pin 10 as the slave select for the digital pot:
const int slaveSelectPin = 10;

void setup() {
  // set the slaveSelectPin as an output:
  pinMode (slaveSelectPin, OUTPUT);
  // initialize SPI:
  SPI.begin();
}

void loop() {
  
    // change the resistance on this channel from min to max:
    for (int level = 0; level < 255; level++) {
      digitalPotWrite(1, level);
      delay(1);
    }
    // wait a second at the top:
  
    // change the resistance on this channel from max to min:
    for (int level = 0; level < 255; level++) {
      digitalPotWrite(1, 255 - level);
      delay(1);
    
    }

}

int digitalPotWrite(int address, int value) {
  // take the SS pin low to select the chip:
  digitalWrite(slaveSelectPin,LOW);
  //  send in the address and value via SPI:
  SPI.transfer(address);
  SPI.transfer(value);
  // take the SS pin high to de-select the chip:
  digitalWrite(slaveSelectPin,HIGH);

}



i also tried messing around with the SPI.begin(); settings but i have achieved nothing.

i'm obviously missing something... any suggestions on what?

also, an image with the digipot connections to the nano
« Last Edit: August 21, 2012, 04:25:22 am by tommyrosa » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

See the Single/Dual digital Potentiometer Library for MCP41xxx, MCP42xxx

arduino-projekte.de

AH_MCP41xxx.h functions
Code:
//INIT
  void init_MCP41xxx (int CS);
  void init_MCP42xxx (int CS, int SHDN, int RS);

//functions
  void setValue(byte value); //value = 0..255
  void setValue(byte value, int potentiometer); //Pot0=0 or Pot1=1
  void shutdown(boolean data); //TRUE or FALSE
  void reset();
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Based on the command byte format from the datasheet, reference:
FIGURE 5-2: Command Byte Format.

Your code:
digitalPotWrite(1, level);

should be:
digitalPotWrite(0x11, level);
Logged

Pages: [1]   Go Up
Print
 
Jump to: