Go Down

Topic: Problem with MCP4241 (Read 94 times) previous topic - next topic

eric_f

Hey everybody

I'm trying to use an MCP4241 digital potentiometer and running into an issue I haven't been able to solve.  This particular device is a two pots in one package (datasheet here)

I've successfully been able to get P0 working without issue, but can't get P1 to change at all, it stays at 78 Kohm measured from wiper to ground.

Since I can get P0 to work, my connections should all be good for the SPI portion.  I've got P1B (pin 5) grounded, P1A (pin 7) to VCC, same for P0, P0B grounded and P0A to VCC.

The relevant code is as follows:
In my library header file:

const static uint8_t ADR_WIPER0 = B00000000;
const static uint8_t ADR_WIPER1 = B00010000;

const static uint8_t CMD_INCREMENT = B00000100;
const static uint8_t CMD_DECREMENT = B00001000;

Those commands start at page 45.

In the cpp file:

void MCP4241::volumeUp() {
   uint8_t left = ADR_WIPER0 | CMD_INCREMENT;
   uint8_t right = ADR_WIPER1 | CMD_INCREMENT;
   SPI.beginTransaction(settings);
   digitalWrite(slave_select_pin, LOW);
   SPI.transfer(right);
   SPI.transfer(left);
   digitalWrite(slave_select_pin, HIGH);
   SPI.endTransaction();
}


According to the datasheet, page 48, "Continuous Commands" you can send multiple commands and as long as they're valid they'll be executed.  I've also tried only sending one command at a time, while "left" works, "right" doesn't.

I've got two pots, a 104 (100K) and a 103 (10K) both showing the exact same problem.  I'm hoping there is something simple in the command I've overlooked.

Any help is appreciated,
Eric

Graynomad

Have you tried separating the commands to prove that the P1 command is OK? Easy to do by commenting out the

SPI.transfer(right);

line.

Divide and conquer with debugging.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

eric_f

I have seperatred. 

void MCP4241::volumeUp() {
   uint8_t left = ADR_WIPER0 | CMD_INCREMENT;
   SPI.beginTransaction(settings);
   digitalWrite(slave_select_pin, LOW);
   SPI.transfer(left);
   digitalWrite(slave_select_pin, HIGH);
   SPI.endTransaction();
}

works perfect, but

void MCP4241::volumeUp() {
   uint8_t right = ADR_WIPER1 | CMD_INCREMENT;
   SPI.beginTransaction(settings);
   digitalWrite(slave_select_pin, LOW);
   SPI.transfer(right);
   digitalWrite(slave_select_pin, HIGH);
   SPI.endTransaction();
}


doesn't work at all

Graynomad

#3
Oct 20, 2015, 02:50 am Last Edit: Oct 20, 2015, 02:57 am by Graynomad
What are ADR_WIPER0 and ADR_WIPER1 defined as?

Best to show the entire code so we can see this stuff, unless it's to large.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

eric_f

They're in the first post, but here they are again.


const static uint8_t ADR_WIPER0 = B00000000;
const static uint8_t ADR_WIPER1 = B00010000;

const static uint8_t CMD_INCREMENT = B00000100;
const static uint8_t CMD_DECREMENT = B00001000;


I've stripped everything down to get to the absolute basics and, that is all the code that has anything to do with my problem. 

I call mcp4241.volumeUp() and mcp4241.volumeDown() from other places, and the function gets called, and only the single side responds.

Just to include it, here's more

SPISettings settings(10000000, MSBFIRST, SPI_MODE3);

MCP4241::MCP4241(uint8_t slave_select_pin) {
   setup_ss(slave_select_pin);
}

void MCP4241::setup_ss(uint8_t slave_select_pin) {
   pinMode(slave_select_pin, OUTPUT);
   digitalWrite(slave_select_pin, HIGH);
   this->slave_select_pin = slave_select_pin;
}

void MCP4241::volumeUp() {
   uint8_t left = ADR_WIPER0 | CMD_INCREMENT;
   uint8_t right = ADR_WIPER1 | CMD_INCREMENT;
   SPI.beginTransaction(settings);
   digitalWrite(slave_select_pin, LOW);
   SPI.transfer(right);
   SPI.transfer(left);
   digitalWrite(slave_select_pin, HIGH);
   SPI.endTransaction();
}

void MCP4241::volumeDown() {
   uint8_t left = ADR_WIPER0 | CMD_DECREMENT;
   uint8_t right = ADR_WIPER1 | CMD_DECREMENT;
   SPI.beginTransaction(settings);
   digitalWrite(slave_select_pin, LOW);
   SPI.transfer(right);
   SPI.transfer(left);
   digitalWrite(slave_select_pin, HIGH);
   SPI.endTransaction();
}


and the header

class MCP4241 {
public:
   MCP4241(uint8_t slave_select);
   void volumeDown();
   void volumeUp();
protected:
   uint8_t slave_select_pin;

   const static uint8_t ADR_WIPER0 = B00000000;
   const static uint8_t ADR_WIPER1 = B00010000;

   const static uint8_t CMD_READ = B00001100;
   const static uint8_t CMD_WRITE = B00000000;
   const static uint8_t CMD_INCREMENT = B00000100;
   const static uint8_t CMD_DECREMENT = B00001000;

   const static uint8_t ADR_VOLATILE = B00000000;
   const static uint8_t ADR_NON_VOLATILE = B00100000;

   const static uint8_t TCON_REGISTER = B01000000;
   const static uint8_t STATUS_REGISTER = B01010000;

   void setup_ss(uint8_t slave_select_pin);
};


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy