SPI wont work for 1 of my sketches

Hello,

I'm trying to transfer data using SPI. I have two sketches, one of which it works and the other doesn't. But they are almost the same and I cant find my mistake.

By not working I mean it does compile and upload, but my slave select output pin never changes.

Here's the code:

This one works:

#include <SPI.h>
const int slaveSelectPin = 47;

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

void loop() {
  for (int channel = 0; channel < 6; channel++) {
    for (int level = 0; level < 255; level++) {
      digitalPotWrite(channel, level);
      delay(100);
    }
    delay(100);
    for (int level = 0; level < 255; level++) {
      digitalPotWrite(channel, 255 - level);
      delay(33);
    }
  }

}

void digitalPotWrite(int address, int value) {
  SPI.beginTransaction(SPISettings(5000000, MSBFIRST, SPI_MODE0));
  digitalWrite(slaveSelectPin, LOW);
  SPI.transfer(address);
  SPI.transfer(value);
  digitalWrite(slaveSelectPin, HIGH);
  SPI.endTransaction();
}

This doesn't:

//Sending Data/Commands to the Display manually
#include <SPI.h>
const int SSPin = 47;

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

void loop()
{
  for(int i = 0; i<100; i++)
  {
    dataTransfer(i);
    delay(100);
  }
}

void dataTransfer(int data)
{
  SPI.beginTransaction(SPISettings(5000000, MSBFIRST, SPI_MODE0));
  digitalWrite(SSPin, LOW);
  SPI.transfer(data);
  SPI.transfer(data*2);
  digitalWrite(SSPin, HIGH);
  SPI.endTransaction();
}

Could someone please help me?

What is this?

SPI.begin;

:sweat_smile: Thank you very much. That was it.
Interesting that it still compiled.

Try setting your compiler warnings to "all" in preferences. Using IDE version 1.6.12 I get:

'
/Users/martin/Documents/Arduino/test/test.ino: In function 'void setup()':
/Users/martin/Documents/Arduino/test/test.ino:8:12: warning: statement is a reference, not call, to function 'SPI.SPIClass::begin' [-Waddress]
   SPI.begin;
            ^
/Users/martin/Documents/Arduino/test/test.ino:8:12: warning: statement has no effect [-Wunused-value]

Sketch uses 932 bytes (2%) of program storage space. Maximum is 32,256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2,039 bytes for local variables. Maximum is 2,048 bytes.

Of course it still compiled.

SPI.begin;

is a reference (an address) that is neither stored nor operated on. This is legal C/C++ code but is useless. Try using a number, such as

42;

which is much the same thing.