SPI faster than shiftOut?

Is SPI faster than shiftOut to convert data from digital to analog? (I am using DAC8512 to convert). How can I learn about how to use SPI? I tried this code, but it didn’t work.

#include <SPI.h>
int ld = 12 , clk = 11 , data = 10, cse = 8, csi = 9,tempo = -10000;
int clr = 13;

void setup() {
  SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE0));
  pinMode(ld, OUTPUT);
  pinMode(clk, OUTPUT);
  pinMode(data, OUTPUT);
  pinMode(cse, OUTPUT);
  digitalWrite(clr, LOW);
  digitalWrite(clr, HIGH);
  digitalWrite(ld, HIGH);
  digitalWrite(cse, LOW);

void loop() {
    digitalWrite(ld, LOW);
    digitalWrite(ld, HIGH);
    digitalWrite(cse, LOW);
    digitalWrite(cse, HIGH);
    digitalWrite(ld, LOW);
    digitalWrite(ld, HIGH);

If I use shiftOut it works…

Thank you all!

Yes, SPI is many times faster than shiftOut.

You have to call SPI.begin() in your setup before you can use it. IIRC, you have to set pin 10 (CS) as an output to operate in SPI master mode.


You can't get to 14 MHz on a 16 MHz Arduino. The fastest the clock will go is 8 MHz. That should be faster than you can do in software unless you can figure out how to shift, output, and loop in two instruction cycles. If you are using one of the faster processors you should check the documentation for maximum clock speed. And check the limits of your D/A chip, too.