Unable to interface with MAX IC Chip using SPI with Arduino Leonardo

I am currently doing a school project to use a MAX 5487 as a digital potentiometer. However, changing the SPI transfer value doesn't change the wiper resistance value at all despite trying both writing to wiper and writing to the NV registers. Is there anything wrong with my code or is the MAX chip not connected properly as the end to end resistance is not the rated value of 10k ohms when I turn it on? Any help is greatly appreciated.
The code is as follows:

#include <SPI.h>
const byte ssPin = 20;
const int maxPos = 256;
const long rAB = 10000;
const byte rWiper = 150;
const byte writepotA = 0x01;
const byte writepotB = 0x02;
const byte writeNVA = 0x11;
const byte writeNVB = 0x12;

void setup() {
  Serial.begin(9600);
  pinMode(ssPin, OUTPUT); 
  digitalWrite(ssPin, LOW);
  SPI.begin();
 }
void loop() {
    setPotWiper(writepotA, 255);
    setPotWiper(writepotB, 255);
    setPotWiper(writeNVA, 255);
    setPotWiper(writeNVB, 255);
    delay(9000);
}
void setPotWiper(int addr, int pos){
  pos =  constrain(pos, 0, 255);
  digitalWrite(ssPin, LOW);
  SPI.transfer(addr);
  SPI.transfer(pos);
  digitalWrite(ssPin, HIGH);
}

It may have nothing to do with the problem you face, but I would have thought that you would need to start off with ssPin set to HIGH in setup().

Not far ago I had a problem with max1300 (16 bit ADC).
Maybe there is an issue specific to all (or many) MAX ICs.
Check how I resolved my problem below (maybe it will help you as well)

The MAX 5487 is active LOW

What do you mean by adding 1 line after command transit though? I have already 1 line after the command transmit as you mentioned, or do I specifically add an SPI.transfer(0); ?

Yes it is. You only drive ssPin low when you are communicating with the MAX5487. That's why I queried your choice of driving it low in setup().

If your MAX5487 powers up in an oddball state, then the change in state of the /CS line resets the SPI interface inside the chip to a known state ready to accept data.

In my opinion, the way you have it in your sketch, the first message you send to the MAX5487 may not succeed as /CS is already low at the start of the data.

EDIT: Looking at the MAX5487 datasheet, I think you may need to use SPI mode 3.

Tried all of what you said. Unfortunately it still doesn't work. Suspect it might be a chip issue

If you can post your latest sketch, then we might see something that may help with the issue.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.