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?