Hi All,
In the past, the SPI parts i've used in projects had ready-made libraries so I could focus on doing science and not worry about spending too much time getting the equipment to work. But now, I've added a new ADC to my setup. I have the circuit completed properly. Datasheet:
http://www.analog.com/static/imported-files/data_sheets/AD7714.pdf
Now, I know it can interface via SPI. I also know how to send commands via such as SPI.transfer(0x5F), which for this chip sets up the next operation to be a read from the data register. However, I'm not too sure about how to read data using SPI.transfer().
So, I have questions. I've seen a few SPI device codes that communicate with sequences of digitalWrite() and digitalRead() rather than the actual SPI commands. Is this preferable? And if so, what's the point of the SPI library at all? It seems like I'd much rather use the SPI library for ease of data transfer.
How do I read data using SPI.transfer()? I've seen some code that looks like dataincoming=SPI.transfer(0); so does that mean passing 0 as SPI.transfer()'s argument means "I want to read this data now"? The data register from this IC is 24 bits long, transferred MSB first. I've read that the SPI library only likes 8 bits at a time, so should I set up a loop such as
for(int i=0; i<3;i++)
{
datareceived[i]=SPI.transfer(0);
data = datareceived[i] << (16-(i*8));
}
I'm not in the lab until later today, and once I get in I can post my test code. So far I'm able to write to all the calibration and mode registers, and correctly poll the DRDY pin and only execute a read when appropriate, but after that I get a constant stream of 0 for my output, even when I have a function generator giving the input appropriate signals.