You tell the chip you're going to start sending it bits by setting the pin of the arduino which is attached to it's chip select pin low, and then setting it high again once you've sent one or more bytes to it.
Take my dac for example. The datasheet shows that it wants 16 bits per command. So I set pin 10 low, send two bytes, and set it high again.
Your chip may want 8-bit commands, or 24-bit commands. So you may send one or three bytes to it before setting the CS pin high again.
I don't know what all those constants are. But they look like they are bit masks for different portions of the command structure. On my dac for example, those 16 bits I send contain 4 configuration bits, and then 12 bits indicating how much voltage it should output.
Here's the code I use to send the dac data btw:
(Or at least, which I used until I determined I really needed to send it data with an interrupt to send it 30,000 updates a second while doing other things.)
void updateDAC() {
static unsigned long lastToggle = 0;
static unsigned long sample = 0;
byte dataHigh, dataLow;
/*
DAC data format:
bit 15 A/B: DACA or DACB Select bit
1 = Write to DACB
0 = Write to DACA
bit 14 BUF: VREF Input Buffer Control bit
1 = Buffered
0 = Unbuffered
bit 13 GA: Output Gain Select bit
1 = 1x (VOUT = VREF * D/4096)
0 = 2x (VOUT = 2 * VREF * D/4096)
bit 12 SHDN: Output Power Down Control bit
1 = Output Power Down Control bit
0 = Output buffer disabled, Output is high impedance
bit 11-0 D11:D0: DAC Data bits
12 bit number “D” which sets the output value. Contains a value between 0 and 4095.
*/
if ((micros()-lastToggle) >= 250) { // 4000hz = 1000000/4000 microseconds ... Does this time need to be divided by 2?
lastToggle = micros();
//if (sample == 0) { sample = 4095; } else { sample = 0; } // Simulate square wave.
sample = random(4096);
// Take the SS pin low to select the DAC.
digitalWrite(pinSPI_SS, LOW);
// Send the 16 bits needed to reconfigure the DAC.
//dataHigh = B00110000 | (sample >> 8);
//dataLow = sample & B11111111;
SPI.transfer(B00110000 | (sample >> 8));
SPI.transfer(sample & B11111111);
// take the SS pin high to de-select the chip:
digitalWrite(pinSPI_SS, HIGH);
}
}
Note that my dac wants the high bits of the 16 bit word first. So I set up the SPI transfer mode elsewhere in the code to send the bits of the bytes in reverse order. And then in my function I make sure I send the high byte of my word first. Your chip may require something different.