This is a follow-up test. The working solution is given below:
1. The bit pattern to be sent to the SPI slave device (i.e. AD5791) does not need to be reversed in order.
2. The SPI mode of AD5791 can be either mode 1 (thanks to mikerj) and mode 3 (thanks to rrosario from this thread
https://ez.analog.com/data_converters/precision_dacs/f/q-a/110156/spi-mode-of-ad5791/326300#326300). Both work equally well in my test program.
3. The LDAC bit should be set to 1 right after writing a value to the DAC register to “trigger” the output. This creates a square pulse on the LDAC pin. This is software triggering using the SPI bus.
4. An alternative way to trigger the output without writing to the LDAC bit is to physically short the LDAC pin and the DGND pin on the AD5791 evaluation board. The DAC output is updated automatically right after writing a value to the DAC register.
5. The interconnection between the AD5791 evaluation board and the Raspberry Pi are 5 wires. They include SCLK, SYNC, SDO, SDIN, and DGND on the evaluation board connecting to SPI0_CLK, SPI0_CE0, SPI0_MISO, SPI0_MOSI, and Ground respectively on the Pi.
6. The jumper settings on the AD5791 evaluation board are as follows: LK1=A, LK2=inserted, LK3=removed, LK4=removed, LK5=inserted, LK6=removed, LK7=removed, LK8=B, LK9=B, LK10=B, LK11=removed.
7. An working test program written in Matlab to drive the AD5791 is shared below (the physical pin of LDAC does not need to be grounded in this case):
clear rpi; clear spidevice;
rpi = raspi('192.168.2.2','xx,'xxx');
enableSPI(rpi);
spidevice = spidev(rpi,'CE0',1,500000);
%% Write to the "software control register" to reset the DAC to power-on state
wdata = ['010000000000000000000100'];
writeAD5791(spidevice,wdata);
%% Write to the "control register" to initialize the DAC to normal state
wdata = ['001000000000000000010010'];
writeAD5791(spidevice,wdata);
%% Write to the "DAC register" to place some non-zero voltage value at the register
wdata = ['000111000000000000000000'];
writeAD5791(spidevice,wdata);
%% Write to the "software control register" to enable the DAC output
wdata = ['010000000000000000000001'];
writeAD5791(spidevice,wdata);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [readdata] = writeAD5791(spidevice,wdata)
readdata = writeRead(spidevice,[bin2dec(wdata(1:8)) bin2dec(wdata(9:16)) bin2dec(wdata(17:end))],'uint8');
pause(0.5);
end
Thanks all!