-1
\$\begingroup\$

I am using MCP4131 with 7 - bit ( 0 - 127 ). Datasheet said that, it can work bit 7 and 8 bit and i definetly need to use it with 8 bit ( 0 - 255 ). Here is my code below;

#include <SPI.h>
byte address = 0x00;
int CS= 10;
void setup()
{
pinMode (CS, OUTPUT);
SPI.begin();

}
void loop()
{
digitalPotWrite(50);
}

int digitalPotWrite(int value)
{
digitalWrite(CS, LOW);
SPI.transfer(address);
SPI.transfer(value);
digitalWrite(CS, HIGH);
}

This is 7 bit code, to make it 8 bit, What should i change in the code ? Or what i need to do ?

Thank You Best Regards

\$\endgroup\$
7
  • \$\begingroup\$ What does the datasheet tell you about its protocol, specifically? \$\endgroup\$
    – user98663
    Commented Dec 9, 2016 at 13:01
  • \$\begingroup\$ <pedantic>7-bit is 0-127 and 8-bit is 0-255</pedantic> \$\endgroup\$ Commented Dec 9, 2016 at 13:02
  • \$\begingroup\$ @Wossname SPI Communication \$\endgroup\$ Commented Dec 9, 2016 at 13:05
  • 1
    \$\begingroup\$ @RogerRowland, this specific device actually does have 257 steps in it's 8bit mode. 0-255 and MAX. Weird. It's because there are 256 resistors internally, which gives 256+1 taps including both ends. I've used this chip before and it's pretty awesome actually. \$\endgroup\$
    – user98663
    Commented Dec 9, 2016 at 13:06
  • \$\begingroup\$ @FiratDagkiran, you need to read the datasheet in detail. You need to research the problem before anyone will help you. \$\endgroup\$
    – user98663
    Commented Dec 9, 2016 at 13:08

2 Answers 2

1
\$\begingroup\$

From page 85 of the datasheet:

datasheet

You can see that the 7-bit and 8-bit options are different devices. So MCP4131 is 7-bit only. It seems you need MCP4151.

\$\endgroup\$
-1
\$\begingroup\$

This depends a lot on what is written in the datasheet on how to use it with the 8-bit feature. However, from your code it looks like you are storing the value in an integer and then writing that. Changing from int to unsigned int should work in this scenario but still a lot depends on what is written in the datasheet. It would be better if you clearly specify what is written in the datasheet regarding the use of 8-bit and 7-bit feature.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.