clockPin of shiftOut()

Hi all,
I’d like to out put the data in dataArray[] bit by bit with a clock 16M, which means the data bit will output every (1/16M) seconds.

I tired the following code:

int clockPin = 8;

int dataPin = 11;
byte dataArray[] ={0xBC,0xAA}; 


void setup() {
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  digitalWrite(clockPin, LOW);
}

void loop() {
    for (int j = 0; j < 2; j++) {
    byte data = dataArray[j];
    shiftOut(dataPin, clockPin, MSBFIRST, data);   
  }
}

I saw the data output correctly but not with the clock 16MHz, which I connected to pin8 from a signal generator. Any suggestion for these? Thanks.

Of course not, the clock pin is an output. The Arduino itself drives it. (At the fastest frequency possible using digitalWrite.) You can't just connect it to an external clock source.
Look up the reference for shiftout, and check the source code.
Even if it were an input, then it would still be impossible​ to get data out at a rate faster than a single instruction cycle.
The fastest you can get is SPI with DMA, which will give you close to 1/2 of the clock speed.

Pieter

PieterP:
Of course not, the clock pin is an output. The Arduino itself drives it. (At the fastest frequency possible using digitalWrite.) You can't just connect it to an external clock source.
Look up the reference for shiftout, and check the source code.
Even if it were an input, then it would still be impossible​ to get data out at a rate faster than a single instruction cycle.
The fastest you can get is SPI with DMA, which will give you close to 1/2 of the clock speed.

Pieter

Thanks Pieter! So I should use other broads that could drive faster? Any suggestion?

What do you want to use it for?
If you would have a board that's orders of magnitude faster than 16MHz, you could do it in software, but an Arduino is too slow. So you need to find a board that has a 16MHz SPI (or I²S) interface with DMA.

Pieter

GBCC1:
So I should use other boards that could drive faster? Any suggestion?

See this thread, from reply #35, 100 bytes transferred in 19.04µs, no dead time with a DUE and the TurboSpi Library for Sam3x: