Issues with SPI library

I’m trying to make digital pot MCP4261 to work with Nano Every, but the megaavr SPI library behaves weirdly. The library in question is this:

The problem is, I can only control wiper0 and can only set its position if the value is 0b1, 0b11, 0b111, 0b1111…etc. i.e all bits are 1. For example 255 will move wiper to one end, but 254, 253, 252… etc wont do anything. Basically the library is broken for Nano Every. When I run the sketch with Arduino Nano, everything works as expected, but Nano uses different SPI library.

Could anyone point me to any alternative Nano Every SPI library please?

What do you do with the SPI library? The term “wiper” fits a servo. but a sevo doesn’t go with SPI!

Hello,

the info is not enough. I have loaded my sketch from the Mega2560 to the NanoEvery. Connected is a display EA-DOGM162. Just adjusted the pins and the thing runs.

Yes, I used SPI as part of the sketch to run TFT display, it worked fine. But I’m having problems with digital potentiometer. It is weird because it is not totally borked but it doesnt work as expected in a long way. I will post my sketch a bit later.

Then you can’t say that SPI doesn’t work. That is misleading.

I never said it doesn’t work, I said it was broken.

I do not follow the logic. If a Dispaly works, the SPI cannot be broken. Besides Arduino.cc will have tested their lib for sure.

Show your code, then we’ll look over it. Show the schematic, then we look over it.

Sorry. What is the difference between ‘broken’ and doesn’t work? I actually speak German.

Here is the sketch I used for both:

#include <SPI.h>
#define SS 8

/*
 Nano Every pin - MCP4261 pin
 13 SCK - 2 SCK
 12 MISO - 13 SDO
 11 MOSI - 3 SDI
 8 SS - CS 1
 Resistance mesured on MCP4261 pins 9,10 for wiper0 and 5,6 for wiper1
*/

void setup() 
{
  pinMode(SS, OUTPUT);
  SPI.begin();

  digitalWrite(SS, LOW);
  
  // works with wiper0
  SPI.transfer(0b00000000); // wiper0 address 0, write command 0 
  SPI.transfer(0b00111111); // 63 sets wiper0 quater way

  // also works with wiper0
  // SPI.transfer(0b00000000); // wiper0 address 0, write command 0 
  // SPI.transfer(0b01111111); // 127 sets wiper0 mid way

  // doesn't work with wiper0 if value is not one of 1, 3, 7, 15, 31, 63, 127, 255 
  // SPI.transfer(0b00000000); // wiper0 address 0, write command 0 
  // SPI.transfer(0b01110011); // 115 doesnt move the wiper0
  
  // doesn't work with wiper1 at all
  // SPI.transfer(0b00010000); // wiper1 address 1, write command 0 
  // SPI.transfer(0b01111111); // doesnt move the wiper1

  // doesn't work with wiper1 at all
  // SPI.transfer(0b00010000); // wiper1 address 1, write command 0 
  // SPI.transfer(0b00111111); // doesnt move the wiper1
 
  digitalWrite(SS, HIGH);
}

// Everything works with Arduino Nano Classic, which uses a different SPI library

void loop() 
{
}

The comments in code should explain the problem.

SS init should always be high level. Otherwise, try the SPI mode. Do you have a data logger or oscilloscope? To see if the data you want goes over the bus.

Makes no difference if I pull SS high at the start. I dont have oscilloscope, would have been ideal to compare output from Classic Nano and Every. I will figure something out how to capture data, thanks.

I did more experiments and examined SPI library, I cant see anything wrong with it, which leads me now to think that maybe Nano Every generates dodgy SPI waveform. Loaded the same sketch on Raspberry Pi Pico and it works just as good as it works on Nano Classic. So potentiometer is not an issue either it understands at least 2 completely different boards. Without oscilloscope I’m afraid I hit the dead end.

Hello,

I still can not imagine that it should not work on Every. SPI with display works. Data is only sent. MCP does not work, although here too only data is sent.

Test this lib.

And please check the wiring again. Not that a cable is missing or similar. You can also test the clock to lower.

Tried that library first thing but the same issues. Tried clock higher, lower, no difference. That library is just the wrapper on top of the SPI that only calculates pot position from resistance or other way round. I stripped it to bare minimum in my sketch. It could be that displays are more tolerant to waveform, and pot is not. Still, without oscilloscope it would be only guess.

I have no more ideas at the moment. Sorry.

A small update. I have since purchased Arduino DUE, I needed a board powerful enough that supports hardware interrupts on many pins. SPI with digital potentiometer works on DUE as expected. I am not going to spend more time trying to figure out why it fails on Every, shame really I was getting to like this board.