Skip to main content
added 12 characters in body
Source Link
Flux
  • 21
  • 4
#include <SPI.h>

// Set Constants
const int adcChipSelectPin = 8;      // set pin 8 as the chip select for the 
ADC:

// Start setup function:
void setup() {

pinMode (adcChipSelectPin, OUTPUT);
// set the ChipSelectPins high initially:
digitalWrite(adcChipSelectPin, HIGH);
// initialise SPI:
SPI.begin();
SPI.setBitOrder(MSBFIRST);         // Not strictly needed but just to be 
sure.
SPI.setDataMode(SPI_MODE0);        // Not strictly needed but just to be 
sure.
Serial.begin(9600);
//Clock Speed: Master clock/divider
//84Mhz/64 =  1.3 MHz
SPI.setClockDivider(SPI_CLOCK_DIV64);

} // End setup function.

// Start loop function:
void loop() {
float voltage[2];
for (int i = 0; i < 3; i++) {
voltage[i] = readAdc(0, 0);
}


}// End of loop function.

//Function to read the ADC, accepts the channel to be read.
float readAdc(int channel, int slave) {

float value;
if (slave == 0) {
noInterrupts(); // disable interupts to prepare to send address data to the 
ADC.
digitalWrite(adcChipSelectPin, LOW); // take the Chip Select pin low to 
select the ADC.


byte FirstByte = 0b10000011;  // b00000111 Isolates the three LSB.  
byte SecondByte = 0b00110000;      // b00001111 isolates the 4 LSB for the 
value returned.

SPI.transfer(FirstByte);

byte response1 = SPI.transfer(SecondByte);
byte response2 = SPI.transfer(0x00);

digitalWrite(adcChipSelectPin, HIGH); // take the Chip Select pin high to 
de-select the ADC.
interrupts(); // Enable interupts.
Serial.println(response1);
Serial.println(response2); 

}

} The serial.prints output 255 consistently. In my experience this means the SPI is configured incorrectly.

#include <SPI.h>

// Set Constants
const int adcChipSelectPin = 8;      // set pin 8 as the chip select for the 
ADC:

// Start setup function:
void setup() {

pinMode (adcChipSelectPin, OUTPUT);
// set the ChipSelectPins high initially:
digitalWrite(adcChipSelectPin, HIGH);
// initialise SPI:
SPI.begin();
SPI.setBitOrder(MSBFIRST);         // Not strictly needed but just to be 
sure.
SPI.setDataMode(SPI_MODE0);        // Not strictly needed but just to be 
sure.
Serial.begin(9600);
//Clock Speed: Master clock/divider
//84Mhz/64 =  1.3 MHz
SPI.setClockDivider(SPI_CLOCK_DIV64);

} // End setup function.

// Start loop function:
void loop() {
float voltage[2];
for (int i = 0; i < 3; i++) {
voltage[i] = readAdc(0, 0);
}


}// End of loop function.

//Function to read the ADC, accepts the channel to be read.
float readAdc(int channel, int slave) {

float value;
if (slave == 0) {
noInterrupts(); // disable interupts to prepare to send address data to the 
ADC.
digitalWrite(adcChipSelectPin, LOW); // take the Chip Select pin low to 
select the ADC.


byte FirstByte = 0b10000011;  // b00000111 Isolates the three LSB.  
byte SecondByte = 0b00110000;      // b00001111 isolates the 4 LSB for the 
value returned.

SPI.transfer(FirstByte);

byte response1 = SPI.transfer(SecondByte);
byte response2 = SPI.transfer(0x00);

digitalWrite(adcChipSelectPin, HIGH); // take the Chip Select pin high to 
de-select the ADC.
interrupts(); // Enable interupts.
Serial.println(response1);
Serial.println(response2);

}

#include <SPI.h>

// Set Constants
const int adcChipSelectPin = 8;      // set pin 8 as the chip select for the 
ADC:

// Start setup function:
void setup() {

pinMode (adcChipSelectPin, OUTPUT);
// set the ChipSelectPins high initially:
digitalWrite(adcChipSelectPin, HIGH);
// initialise SPI:
SPI.begin();
SPI.setBitOrder(MSBFIRST);         // Not strictly needed but just to be 
sure.
SPI.setDataMode(SPI_MODE0);        // Not strictly needed but just to be 
sure.
Serial.begin(9600);
//Clock Speed: Master clock/divider
//84Mhz/64 =  1.3 MHz
SPI.setClockDivider(SPI_CLOCK_DIV64);

} // End setup function.

// Start loop function:
void loop() {
float voltage[2];
for (int i = 0; i < 3; i++) {
voltage[i] = readAdc(0, 0);
}


}// End of loop function.

//Function to read the ADC, accepts the channel to be read.
float readAdc(int channel, int slave) {

float value;
if (slave == 0) {
noInterrupts(); // disable interupts to prepare to send address data to the 
ADC.
digitalWrite(adcChipSelectPin, LOW); // take the Chip Select pin low to 
select the ADC.


byte FirstByte = 0b10000011;    
byte SecondByte = 0b00110000;      

SPI.transfer(FirstByte);

byte response1 = SPI.transfer(SecondByte);
byte response2 = SPI.transfer(0x00);

digitalWrite(adcChipSelectPin, HIGH); // take the Chip Select pin high to 
de-select the ADC.
interrupts(); // Enable interupts.
Serial.println(response1);
Serial.println(response2); 

}

The serial.prints output 255 consistently. In my experience this means the SPI is configured incorrectly.

Inlined the link and list formatting
Source Link
Greenonline
  • 3.1k
  • 7
  • 34
  • 48

I am having trouble configuring Arduino Due SPI to an ADC. Here is a link to the ADC: https://www.analog.com/media/en/technical-documentation/data-sheets/AD7490.pdf ADC.

Here is how I have the pins connected: +3.3V > 7490 pin 22 Vin +3.3V > 7490 Vref DUE CS (8) > 7490 pin 20 SS - slave select) DUE SCK > 7490 pin 16 (SCK - clock) DUE MOSI > 7490 pin 19 (MOSI - data out) Ground > 7490 pin 24( all gnds tied together DUE MISO > 7490 pin 15

  • +3.3V > 7490 pin 22 Vin
  • +3.3V > 7490 Vref
  • DUE CS (8) > 7490 pin 20 SS - slave select)
  • DUE SCK > 7490 pin 16 (SCK - clock)
  • DUE MOSI > 7490 pin 19 (MOSI - data out)
  • Ground > 7490 pin 24 (all ground lines are tied together)
  • DUE MISO > 7490 pin 15

Any pointers are appreciated.

Cheers!

I am having trouble configuring Arduino Due SPI to an ADC. Here is a link to the ADC: https://www.analog.com/media/en/technical-documentation/data-sheets/AD7490.pdf

Here is how I have the pins connected: +3.3V > 7490 pin 22 Vin +3.3V > 7490 Vref DUE CS (8) > 7490 pin 20 SS - slave select) DUE SCK > 7490 pin 16 (SCK - clock) DUE MOSI > 7490 pin 19 (MOSI - data out) Ground > 7490 pin 24( all gnds tied together DUE MISO > 7490 pin 15

Any pointers are appreciated.

Cheers!

I am having trouble configuring Arduino Due SPI to an AD7490 ADC.

Here is how I have the pins connected:

  • +3.3V > 7490 pin 22 Vin
  • +3.3V > 7490 Vref
  • DUE CS (8) > 7490 pin 20 SS - slave select)
  • DUE SCK > 7490 pin 16 (SCK - clock)
  • DUE MOSI > 7490 pin 19 (MOSI - data out)
  • Ground > 7490 pin 24 (all ground lines are tied together)
  • DUE MISO > 7490 pin 15

Any pointers are appreciated.

Source Link
Flux
  • 21
  • 4

Trouble configuring Arduino Due SPI to ADC

I am having trouble configuring Arduino Due SPI to an ADC. Here is a link to the ADC: https://www.analog.com/media/en/technical-documentation/data-sheets/AD7490.pdf

Here is how I have the pins connected: +3.3V > 7490 pin 22 Vin +3.3V > 7490 Vref DUE CS (8) > 7490 pin 20 SS - slave select) DUE SCK > 7490 pin 16 (SCK - clock) DUE MOSI > 7490 pin 19 (MOSI - data out) Ground > 7490 pin 24( all gnds tied together DUE MISO > 7490 pin 15

Below is my code, I feel like I am writing the correct bits into the register. The problem I think I'm having is getting the timing write. The code is a simple attempt to read a single channel.

#include <SPI.h>

// Set Constants
const int adcChipSelectPin = 8;      // set pin 8 as the chip select for the 
ADC:

// Start setup function:
void setup() {

pinMode (adcChipSelectPin, OUTPUT);
// set the ChipSelectPins high initially:
digitalWrite(adcChipSelectPin, HIGH);
// initialise SPI:
SPI.begin();
SPI.setBitOrder(MSBFIRST);         // Not strictly needed but just to be 
sure.
SPI.setDataMode(SPI_MODE0);        // Not strictly needed but just to be 
sure.
Serial.begin(9600);
//Clock Speed: Master clock/divider
//84Mhz/64 =  1.3 MHz
SPI.setClockDivider(SPI_CLOCK_DIV64);

} // End setup function.

// Start loop function:
void loop() {
float voltage[2];
for (int i = 0; i < 3; i++) {
voltage[i] = readAdc(0, 0);
}


}// End of loop function.

//Function to read the ADC, accepts the channel to be read.
float readAdc(int channel, int slave) {

float value;
if (slave == 0) {
noInterrupts(); // disable interupts to prepare to send address data to the 
ADC.
digitalWrite(adcChipSelectPin, LOW); // take the Chip Select pin low to 
select the ADC.


byte FirstByte = 0b10000011;  // b00000111 Isolates the three LSB.  
byte SecondByte = 0b00110000;      // b00001111 isolates the 4 LSB for the 
value returned.

SPI.transfer(FirstByte);

byte response1 = SPI.transfer(SecondByte);
byte response2 = SPI.transfer(0x00);

digitalWrite(adcChipSelectPin, HIGH); // take the Chip Select pin high to 
de-select the ADC.
interrupts(); // Enable interupts.
Serial.println(response1);
Serial.println(response2);

}

Any pointers are appreciated.

Cheers!