So I'm trying to use SPI.transfer16 to communicate with an AD9834 microcontroller to send it five control words, two bytes each, as described here. My code looks like this at the moment:
Serial.begin(9600);
const int SS = 10;
pinMode(SS, OUTPUT);
SPI.begin(); // SPI setup section:
SPI.beginTransaction(SPISettings(40000000, MSBFIRST, SPI_MODE3));
writeWord16(0x2100, SS);
Serial.println("Reset asserted");Serial.println();delay(5000);
writeWord16(0x71E1, SS);
Serial.println("Freq0 LSB sent");Serial.println();delay(1000);
writeWord16(0x4051, SS);
Serial.println("Freq0 MSB sent");Serial.println();delay(1000);
writeWord16(0xC000, SS);
Serial.println("Phase0 sent");Serial.println();delay(1000);
writeWord16(0x2000, SS);
Serial.println("Reset unasserted");Serial.println();delay(1000);
Where the writeWord16 function is as follows:
void writeWord16(int Word, int SSnum)
{
digitalWrite(SSnum, LOW);
Serial.print("Using SS pin ");Serial.println(SSnum);
SPI.transfer16(Word);
digitalWrite(SSnum, HIGH);
Serial.println("Control word written");
}
The problem is that it doesn't seem to be actually getting anything to the microcontroller I'm working with. I've done some looking on google, but a lot of what I've found has been outdated and frankly just confused me more.
I've got a few ideas what might be wrong, but I'd like some insight as to what might actually help. First, I'm not sure if I need to be pulling SS low and then high again before and after the transfer16 function in writeWord16. Does the transfer16 function take care of that itself? Second, do I need to format the data I'm sending in any particular manner? (i.e. are 0x2100, 8448, and 0b0010000100000000 all equivalent?) The examples I've found online have used them pretty interchangeably, so I assume so, but I'm not sure.
Assuming that's all correct, what other problems might I be running into? Like I said earlier, I don't think anything's actually making it through to the microcontroller. I assume this is because of some syntax or misuse of the function on the Arduino's end, but I can't figure out what that might be.
I'm using an Arduino Nano, D10 is hooked up to SS, D11 to MOSI, and D13 to SCLK. Here's the datasheet for the AD9834 I'm trying to interface with: http://www.analog.com/media/en/technical-documentation/data-sheets/AD9834.pdf