SPI Output Bit Controlling

Hi all,

I'm trying to write SPI control codes as following. My IC only wants to read 26 bits, which means only 0x20, 0x0C, 0x00, and B11 are needed. But as written, Arduino broad will output B00000011(8 bits) instead of B11(2 bits) only (the five upper bits B00000 are not wanted). How can I output only 26 bits? Thanks!

#include <SPI.h>
uint8_t     g_Buffer2[]={0x20, 0x0C, 0x00, B11}; //0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1

void setup()
{
  // setup SPI
  Serial.begin(9600);
  SPI.begin();
  //CLOCK data pin 13
  SPI.setClockDivider(SPI_CLOCK_DIV8);
}

void loop()
{

 //SS pin 10
 digitalWrite(SS,LOW);
 //MOSI data pin 11
 for(int i=0; i< sizeof(g_Buffer2); i++)
   SPI.transfer (g_Buffer2[i]);
 //disable slave
 digitalWrite(SS,HIGH);
}

SPI is byte oriented so it deals in multiples of 8 bits. What device/chip are you trying to communicate with that expects 26 bits?

Also, your declaration of "b11" doesn't mean you"ll get only two bits, you are just using two bits of an eight bit value. It is no different than declaring it as 0x03.

avr_fred:
SPI is byte oriented so it deals in multiples of 8 bits. What device/chip are you trying to communicate with that expects 26 bits?

I'm trying to control a freq. synthesizer SKY73103-11, which has 5 registers with 26 bits each inside.

That is not an SPI device in any way, shape or form. You'll have write your own code to "bit-bang" the clock, serial data and LE bit.