# how to SPI 16 bits, 6 command bits, + 10 data bits

My AD5292 Digital pot takes a 16 bit command via SPI. First should be 6 bits for the command, and 10 bits for the data. It is a 1024 step pot, so it requires 10 bits for the data.

The SPI library sends 8 bits at a time. So I have to come up with some way to combine the command and the data into one value, then split that value into two parts to transfer one at a time.

So if the command bit is 001010 and the data bits are 1010101010 I need to combine them so that I get 0010101010101010, then break that up into 00101010 and 10101010.

The first value would be 42 in decimal. The second value would be 170.
So then I would use the SPI transfer function:

SPI.transfer(42);
SPI.transfer(170);

My problem is trying to come up with a way to combine and then split the result into two 8 bit commands.

I think I could build an array and then extract bits back out of it, but I'm not sure how to do that. I'm looking for ideas.

``````int command = 0b001010;
int data = 0b1010101010;

int output = (command << 10) + data;

byte outOne = highByte(output);
byte outTwo = lowByte(output);
``````

Thanks Paul. I was just investigating using bitwise operations, I think I would have figure it out eventually, but you probably saved me a good day's worth of work. I'll test that out, but I believe it will work.