Graynomad:
There's no reason the two shouldn't both work on the hardware SPI as long as you deal with the SS issue. OTOH your code may be a bit simpler if you use shiftOut() because your won't have to deal with SS.As long as you don't need speed I see no real advantage either way.
At what rate do you need to write to the DAC?
Rob
Well I want to put my controller in a loop that lasts 10 ms (at least, I haven't determined my sampling interval yet), so at most 100 times a second. Does the DAC hold the last value received until another one is received? I think I read that it does, somewhere...
I'm a bit worried about the Ethernet Shield having one of its SPI pins low for long durations of time, I think it's the SS pin, which would mean that I can't use the DAC while the E. Shield is doing that.
CrossRoads:
SPI, fast & simple
http://ww1.microchip.com/downloads/en/DeviceDoc/22248a.pdfdigitalWrite ( DAC_SS, LOW ); // connects to device's LDAC pin
SPI.transfer ( command_data );
SPI.transfer ( low_data );
digitalWrite ( DAC_SS, LOW );where the upper 4 bits of command_data are 0111 00xx typical per datasheet page 24, with xx being the upper 2 bits of data
and low_data is the remaining 8 bits of data.
Sorry, why is the LDAC pin being used as the SS, rather than the CS pin? I don't follow ![]()
CrossRoads:
If your analog data is stored as an int, then the data to be transferred out could be set up as follows:
your_data = your_data | B0111 0000 0000 0000; // sets the needed command bits high, leaves your 10 bit data alone
your_data = your_data & B0111 0011 1111 1111; // clears the needed command bits low, leaves your 10 bit data alone
(spaces shown for clarity only)digitalWrite ( DAC_SS, LOW ); // connects to device's LDAC pin
SPI.transfer ( highByte( your_data ) );
SPI.transfer ( lowByte( your_data ) );
digitalWrite ( DAC_SS, HIGH );
I was using 10-bit PWM, so my analogWrite() values would be an int from 0 to 1023. Do the 2 your_data lines convert the integer to binary?
I have a feeling this is something I will need to test with a breadboard when my chips get here...
Thanks for the help so far! ![]()