Friday 24 January 2020

microcontroller - Send more than one value via SPI/arduino, MAX5483, 10-bit digi-poti


With help from efox29 I worked out to control the MAX5483, 10-bit digital potentiometer (data sheet here) with an arduino using SPI. Now how can I trigger more than one value?


I tried to do that with a simple for-loop, but it doesn't work. To be precise it produces a strange resistance value (68 Ohm). And even just putting a delay seems to cause the same issues..


For example


digitalPotWrite(197); //  

delay(10000);
digitalPotWrite(60); //
delay(10000);

Should change the resistance between 2.1k Ohm and 688 Ohm. I assume that, since by putting just


digitalPotWrite(197);

or


digitalPotWrite(60); 


alone without delay(10000); I can measure this values with my multimeter between the pin 10 and 11 of MAX5483. But by putting it all together like I tried above, I strangely measure only 65-68 Ohm. This doesn't change by only putting the following lines:


digitalPotWrite(197); //  
delay(10000);

Here the measured value (between pin 10 and 11) is still 68 Ohm.. Here is the complete code:


#include  
const int csPin = 3;
const int selPin = 2;

void setup() {


SPI.begin();
SPI.setBitOrder(MSBFIRST); //We know this from the Data Sheet
SPI.setDataMode(SPI_MODE2);

pinMode(csPin,OUTPUT);
digitalWrite(csPin, LOW);

pinMode(selPin,OUTPUT);
digitalWrite(selPin, HIGH);


}

void loop()
{
//"sweep" small range (from 1.7 to 2.1 KOhm)
// 158 to 197
//
// for (int i=158; i < 211; i++){
// delay(1000);

// digitalPotWrite(i); //
// }

digitalPotWrite(197); //
delay(100); // seems to cause issues.. without this line it works

}

void digitalPotWrite(int value) {
digitalWrite(csPin, LOW);

delay(1);
byte command=0x0;
byte byte0 = (value & 0x03) << 6;
byte byte1 = (value & 0x3FC) >> 2;
SPI.transfer(command);
SPI.transfer(byte1);
SPI.transfer(byte0);
delay(1);
digitalWrite(csPin, HIGH);
}


Answer



In void setup() you need to change the line


SPI.setDataMode(SPI_MODE2); 

into


SPI.setDataMode(SPI_MODE0); 

No comments:

Post a Comment

arduino - Can I use TI&#39;s cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...