Hello Everyone,
I have an ADS1256 High-Precision AD/DA shield for Raspberry Pi.
I have connected it to an Arduino Uno.
fig.1 shows my adc board.
fig.2 & fig.3 shows connections.
my code is:
/* ADS1256
CLK - pin 13
DIN - pin 11 (MOSI)
DOUT - pin 12 (MISO)
CS - pin 10
DRDY - pin 9
RESET- pin 8 (or tie HIGH?)
DVDD - 3V3
DGND - GND
*/
#define cs 10 // chip select
#define rdy 9 // data ready, input
#define rst 8 // reset pin
#define pwd 7 // power down
#define SPISPEED 1000000
// 1250000
#include <SPI.h>
void setup()
{
Serial.begin(115200);
pinMode(cs, OUTPUT);
digitalWrite(cs, LOW); // tied low is also OK.
pinMode(rdy, INPUT);
pinMode(rst, OUTPUT);
digitalWrite(rst, LOW);
delay(1); // LOW at least 4 clock cycles of onboard clock. 100 microsecons is enough
digitalWrite(rst, HIGH); // now reset to deafult values
delay(500);
SPI.begin(); //start the spi-bus
delay(500);
//init
digitalWrite(pwd, LOW);
//while (digitalRead(rdy)) {} // wait for ready_line to go low
SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_MODE1)); // start SPI
delayMicroseconds(10);
//Reset to Power-Up Values (FEh)
SPI.transfer(0xFE);
delayMicroseconds(100);
byte status_reg = 0 ; // address (datasheet p. 30)
//PGA SETTING
//1 ±5V
//2 ±2.5V
//4 ±1.25V
//8 ±0.625V
//16 ±312.5mV
//32 ±156.25mV
//64 ±78.125mV
//byte status_data = 0x01; //status: Most Significant Bit First, Auto-Calibration Disabled, Analog Input Buffer Disabled
byte status_data = 0b00000110;
SPI.transfer(0x50 | status_reg);
SPI.transfer(0x00); // 2nd command byte, write one register only
SPI.transfer(status_data); // write the databyte to the register
delayMicroseconds(10);
byte adcon_reg = 2; //A/D Control Register (Address 02h)
byte adcon_data = 0x20; // 0 01 00 000 => Clock Out Frequency = fCLKIN, Sensor Detect OFF, gain 1
SPI.transfer(0x50 | adcon_reg);
SPI.transfer(0x00); // 2nd command byte, write one register only
SPI.transfer(adcon_data); // write the databyte to the register
delayMicroseconds(10);
// Set sampling rate
byte drate_reg = 3;
byte drate_data = 0b10000010; // 100SPS
SPI.transfer(0x50 | drate_reg);
SPI.transfer(0x00);
SPI.transfer(drate_data);
delayMicroseconds(10);
SPI.transfer(0xF0);
delay(5000);
// digitalWrite(cs, HIGH);
Serial.println("configured, starting");
}
void loop()
{
unsigned long adc_val =0;
float mV = 0;
// digitalWrite(cs, LOW);
SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_MODE1)); // start SPI
delayMicroseconds(10);
//while (digitalRead(rdy)) {} ;
byte data = 0b00000001;//DIFF 1
SPI.transfer(0x50 | 1); // MUX register
SPI.transfer(0x00); // 2nd command byte, write one register only
SPI.transfer(data); // write the databyte to the register
delayMicroseconds(10);
//SYNC command 1111 1100
SPI.transfer(0xFC);
delayMicroseconds(10);
//WAKEUP 0000 0000
SPI.transfer(0x00);
delayMicroseconds(10);
SPI.transfer(0x01); // Read Data 0000 0001 (01h)
delayMicroseconds(10);
adc_val = SPI.transfer(0);
adc_val <<= 8; //shift to left
adc_val |= SPI.transfer(0);
adc_val <<= 8;
adc_val |= SPI.transfer(0);
delayMicroseconds(10);
// digitalWrite(cs, HIGH);
SPI.endTransaction();
//The ADS1255/6 output 24 bits of data in Binary Two's
//Complement format. The LSB has a weight of
//2VREF/(PGA(223 − 1)). A positive full-scale input produces
//an output code of 7FFFFFh and the negative full-scale
//input produces an output code of 800000h.
if(adc_val > 0x7fffff){ //if MSB == 1
adc_val = (16777215ul - adc_val) + 1; //do 2's complement
//Serial.print("-");
}
else
{
//Serial.print("+");
}
mV = adc_val*0.000596046; // 8388607 = +5.000v /
Serial.println(mV);
delay(100);
}
As I want to read to data from 1 channels with single ended measurements. While analog input 1 is connected to the variable resistance (embedded on the ADS1256 High-Precision AD/DA shield board) and i change it but i get only 0 as a output in the serial monitor.
If anyone can guide me here it can help me to complete my project.
It would be really helpful to get some guidance.
Thanks