Trouble setting up SPI on Particle P1 [Solved]

Hi,
I’m very new to particle, and I was having some trouble setting up the SPI interface.
The way that the hardware is set up, I only have access to SPI1, and the default slave select pin is connected to “DAC” (numeric pin 24).

I have the pin configuration set up as so:

#define COL_CLK                D4 // numeric pin 52 
#define COL_DATA              D2 // numeric pin 45 (this is MOSI)
#define COL_MISO              D3 // number pin 51 
#define COL_LE_N              A0 // numeric pin 50
#define COL_CLR                A2 // numeric pin 49
#define COL_SS                  DAC //numeric pin 24

Then following the particle datasheet, I have in my setup I have:

// Initialize SPI1 to transfer data to COL 
SPI1.begin(COL_SS);
SPI1.setBitOrder(MSBFIRST);
SPI1.setClockSpeed(10, MHZ);
SPI1.setDataMode(SPI_MODE3);

And then in my main loop I have:

digitalWrite(COL_SS, LOW);  //slave select 
SPI1.transfer(0xAA); //transfer 1010 1010    
digitalWrite(COL_SS, HIGH);
delay(1000);

I tried probing the output (COL_DATA pin D2 numeric pin 45) however I just see the output be constantly 0 (GND). (I have also tried transferring “0xFF” and when I probe the output I get a constant high signal as expected.)
Any feedback or insight would be really appreciated, thanks!

@m23rashid, try again but put the SPI1.begin() statement after the SPI.set calls. What SPI device are you driving?

4 Likes

@peekay123 Thanks! Changing SPI1.begin() to the beginning did the trick.

2 Likes

@peekay123 thanks for helping out!
@m23rashid Welcome to the Community, there are a lot of great posts and links here that can help you out!

2 Likes