12-02-2018 03:57 PM - edited 12-02-2018 03:58 PM
I am currently trying out myRIO and SPI communication.
I have tested my code on an arduino DUE and want to use the ADS1256 on the myRIO.
Anyone know how to do that?
/* 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 // may omit
#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(cs, 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);
}
12-03-2018 02:35 AM
12-04-2018 02:29 PM
Tnx for the info.
I am looking at it now.
Here is my New start-up, config and run
12-04-2018 03:18 PM
New start-up, config and run is wrong on previous post. Working on it
12-25-2020 05:10 AM
Did you succeed?
I have been looking for related documents, if possible can you share your program?
01-04-2021 12:21 AM
Sorry for the delay. I have not been working on it for some time, but got some of the codes to work.
I can see if I find it again and send you a link.
01-04-2021 03:01 AM
It's ok~
thank you very much .
Looking forward to your news~
01-13-2021 12:24 AM
Sorry for the delay.
It is not a loot but a start.
01-14-2021 12:55 AM
Hello, thank you very much for your program, but I use spi. But IS ok, thank you~ I want to know that asd1256 has an i2c version?
01-18-2021 07:04 AM
I dont know, sorry