Problem with the simplest SPI commands

Hi guys, I am trying to control an EVAL-AD5764 DAC chip with spi via arduino.
I've got a lovely example via the Seekat project at opendacs.com.

However, I am having trouble simply getting the most basic version of SPI.transfer to work.
The first byte sends predictably and the other two are silent. Dont know why.

The ss pin is blue. The clk pin is green and shows 24 bits. The yellow mosi pin only shows the data of the first byte.

#include <SPI.h>

void setup() {
  pinMode(53, OUTPUT); // set the SS pin as an output
  SPI.begin();         // initialize the SPI library
  SPI.beginTransaction(SPISettings(SPI_CLOCK_DIV32, MSBFIRST, SPI_MODE1));
}

void loop() {


  digitalWrite(53, LOW);            // set the SS pin to LOW
  SPI.transfer(0b10101010);             
  SPI.transfer(0b11001100);      
  SPI.transfer(0b11101110);
  digitalWrite(53, HIGH);           // set the SS pin HIGH
}

I have searched for examples and tried several delays and different things but I'm pretty confused why this wont work.
Thank you so much for any help.

Try the following codes:

void loop() {


  digitalWrite(53, LOW);            // set the SS pin to LOW
  byte x1 = SPI.transfer(0b10101010);
  Serial.println(x1, HEX);        
     
  byte x2 = SPI.transfer(0b11001100);      
  Serial.println(x2, HEX)

  byte x3 = SPI.transfer(0b11101110);
 Serial.println(x3, HEX);

 delay(1000);
  //digitalWrite(53, HIGH);           // set the SS pin HIGH
}

Me 2 :frowning:

Are you sure that you show MOSI, not MISO by accident?

Chech

Check MEGA's SPI connection against Fig-1.
spiMegaConn
Figure-1:

You guys are great. I thought I had checked both miso and mosi lines but it takes someone telling you to do so directly that makes the difference. I was indeed watching the wrong line and the code does work correctly when watching mosi.

Thanks so much for the help. :smiling_face:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.