Hello,
Since this is my first time working with SPI I have a few questions.
My problem is that I don't know how to read and write data to the SPI device (in this case ADS841, 16-bit ADC). The code I have now is just setting up the SPI communication:
#include <SPI.h>
int spi_SS = 10;
int spi_MOSI = 11;
int spi_MISO = 12;
int spi_SCK = 13;
void setup() {
SPI.begin();
digitalWrite(spi_SS, HIGH);
}
void loop() {
SPI.beginTransaction(SPISettings(2400000, MSBFIRST, SPI_MODE0));
digitalWrite(spi_SS, LOW);
//Other SPI code
digitalWrite(spi_SS, HIGH);
SPI.endTransaction();
}
I got the frequency/MSB/Mode from the datasheet.
This is the timing diagram (The ADC can also be used with an internal clock mode or a 24-clock conversion rate, see datasheet):
So from what I understand, the DIN/MOSI has to send 8 bits of data on the rising edge. After that there is 1 clock cylce where no the ADC is processing the send data. Then (in the next 17 to 25 bits) on every clk cycle the DOUT is sending data that the MISO has to read. After that only the clock is cycling to the 32th bit and the protocol is done.
The only problem is that I don't know what to do now after the SPI.beginTransaction(); in code.
If someone could explain how this process relates to code in arduino I would be happy.
Thanks.
EDIT:
After some more reading on the SPI.transfer(data); function, I see that you can send the data (1 byte) in the 'data' variable and then the function returns the received data. How does the function know when to stop reading the data / does it only read the 16 bits that I need from the ADC?
