I am working on a project which use my Arduino Due to communicate via SPI with AD7616 ADC via only SDOA of the ADC(single SPI mode)
I had programmed to send 0x86BB as an instruction to call the interface test function, and was expecting 0xAAAA as a return. However, I am getting only the results showing in the figure below: (It reads 255 on Arduino only)
The waveform shows a strange capacitor discharging on the scope, which shouldn't happen, I had tested the AD with two different Arduinos and two copies of ADC chip and they had shown the same waveform. Also, the return signal of the AD did change with the value I feed in. I am running this through SPI mode 2.
Does anyone know what is the cause of this strange charging?
I will take a SWAG and say your wave form is correct. The blue trace appears to be on the data line and when the transmitter is finished sending it goes into open drain mode. Wiring capacatance could cause that. You could put something in the 4K range as a pull down and see if that solves your problem.
After verifying the waveform on the scope, I found that the strange return problem is probably cause by incorrect SPI mode, I made the Due works on SPI mode 2, but seems from the scope it is not working on the designated mode or the clock speed. Seems it is still running with 4MHz clock and SPI mode 0.
I tried to use the old style code such as SPI.setDataMode(SPI_MODE2), but the results are still similar.
Below is my code for the reference:
#include <SPI.h>
void setup() {
// put your setup code here, to run once:
pinMode(4, OUTPUT); //set pin 4 as SER1W
pinMode(6, OUTPUT); //set pin 6 as reset
SPI.begin(10); //initialize SPI library
// REG_PIOA_PUER = 0x1C000000; //Turn on the internal PU pot for SPI pins
// REG_PIOA_PUER = 1 << 25; //PU OF MISO
// REG_PIOA_PUER = 1 << 26; //PU OF MOSI
// REG_PIOA_PUER = 1 << 27; //PU OF SCK
// REG_PIOA_PUER = 1 << 28; //PU OF CS
Serial.begin(9600);
digitalWrite(4, LOW); //SER1W low, select as 1 SDO output
delay(200);
digitalWrite(6, LOW);//reset AD7616, startup sequence start.
delay(2);
digitalWrite(6, HIGH);//end reset, end of startup sequence.
delay(1000);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(SS, HIGH); // ensure SS stays high
uint16_t dataInt;
delay(500);
digitalWrite(SS, LOW); //start of SPI conversation
SPI.beginTransaction(SPISettings(100000, MSBFIRST, SPI_MODE2));
SPI.transfer16(10, 0b1000011010111011); // send a write command to the AD7616 to trigger interface check mode, expect to read 0XAAAA
uint16_t receivedInt = SPI.transfer16(10, dataInt); //read data from AD7616
Serial.println(0b1000011010111011);//34491
Serial.println(receivedInt); // print the SPI received value to check
digitalWrite(SS,HIGH); //set pin 10 high
SPI.endTransaction();
}
Update: I tried to alter the AVR register directly to forcibly set the SPI mode on the Arduino, but then the Due is stuck and does not give any results.