hello
ADS1256 register read and write work properly but i have problem to read the data from ads1256 its show garbage value.
i send my code here.
#include <SPI.h>
#define DRDY_PIN 2
#define CS_PIN 7
#define NOP 0xFF
#define MISO_PIN 12
#define MOSI_PIN 11
#define SCK_PIN 13
#define WREG 0x50
#define RREG 0x10
#define RDATA 0x01 //Read data once
#define RDATAC 0x03 //Read data continously
#define SDATAC 0x0F //Stop reading data continously
#define WAKEUP 0x00 //Exit Sleep Mode
#define SYNC 0xFC
#define NOP 0xFF
#define ORDER_MSB // Most significant Bit first (default)
#define SPI_SPEED 4800000
#define PGA 1 // Programmable Gain = 1
#define VREF 2.5 // Internal reference of 2.048V
#define VFSR VREF*2/PGA
#define FSR (((long int)1<<23)-1)
//const int dataReadyPin = 6;
volatile byte MSB;
volatile byte data;
volatile byte LSB;
//volatile char SPI_RX_Buff[3];
//volatile byte *SPI_RX_Buff_Ptr;
uint8_t CONFIG_REG0_ADDRESS;
uint8_t CONFIG_REG1_ADDRESS;
uint8_t CONFIG_REG2_ADDRESS;
uint8_t CONFIG_REG3_ADDRESS;
uint8_t CONFIG_REG4_ADDRESS;
uint8_t CONFIG_REG5_ADDRESS;
uint8_t CONFIG_REG6_ADDRESS;
uint8_t CONFIG_REG7_ADDRESS;
uint8_t CONFIG_REG8_ADDRESS;
uint8_t CONFIG_REG9_ADDRESS;
uint8_t CONFIG_REG10_ADDRESS;
uint8_t Config_Reg0 ;
uint8_t Config_Reg1 ;
uint8_t Config_Reg2;
uint8_t Config_Reg3 ;
uint8_t Config_Reg4 ;
uint8_t Config_Reg5 ;
uint8_t Config_Reg6;
uint8_t Config_Reg7 ;
uint8_t Config_Reg8 ;
uint8_t Config_Reg9;
uint8_t Config_Reg10 ;
volatile int DRDY_state;
void setup()
{
delayMicroseconds(500);
delayMicroseconds(500);
pinMode(MOSI_PIN, OUTPUT);
pinMode(MISO_PIN, INPUT);
pinMode(CS_PIN, OUTPUT);
pinMode(DRDY_PIN, INPUT);
pinMode(SCK_PIN, INPUT);
digitalWrite(CS_PIN, HIGH);
digitalWrite(SCK_PIN, LOW);
volatile int DRDY_state = HIGH;
SPI.begin();
Serial.begin(9600);
void writeRegister(uint8_t address, uint8_t value);
uint8_t readRegister(uint8_t address);
SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE1));
void DRDY_Interuppt();
attachInterrupt(digitalPinToInterrupt(DRDY_PIN), DRDY_Interuppt,FALLING);
CONFIG_REG0_ADDRESS=0x00;
CONFIG_REG1_ADDRESS=0x01;
CONFIG_REG2_ADDRESS=0x02;
CONFIG_REG3_ADDRESS=0x03;
CONFIG_REG4_ADDRESS=0x04;
CONFIG_REG5_ADDRESS=0x05;
CONFIG_REG6_ADDRESS=0x06;
CONFIG_REG7_ADDRESS=0x07;
CONFIG_REG8_ADDRESS=0x08;
CONFIG_REG9_ADDRESS=0x09;
CONFIG_REG10_ADDRESS=0x0A;
delay(100);
writeRegister(0x00, 0x01);
delayMicroseconds(50);
writeRegister(0x01, 0x0F);
delayMicroseconds(50);
writeRegister(0x02, 0x20);
delayMicroseconds(50);
writeRegister(0x03, 0xA2);
delayMicroseconds(50);
writeRegister(0x04, 0xE0);
delayMicroseconds(50);
writeRegister(0x05, 0x00);
delayMicroseconds(50);
writeRegister(0x06, 0x00);
delayMicroseconds(50);
writeRegister(0x07, 0x00);
delayMicroseconds(50);
writeRegister(0x08, 0x00);
delayMicroseconds(50);
writeRegister(0x09, 0x00);
delayMicroseconds(50);
writeRegister(0x0A, 0x00);
delayMicroseconds(50);
// digitalWrite(CS_PIN,HIGH); //release chip, signal end transfer
Config_Reg0 = readRegister(CONFIG_REG0_ADDRESS);
delayMicroseconds(50);
Config_Reg1 = readRegister(CONFIG_REG1_ADDRESS);
delayMicroseconds(50);
Config_Reg2 = readRegister(CONFIG_REG2_ADDRESS);
delayMicroseconds(50);
Config_Reg3 = readRegister(CONFIG_REG3_ADDRESS);
delayMicroseconds(50);
Config_Reg4 = readRegister(CONFIG_REG4_ADDRESS);
delayMicroseconds(50);
Config_Reg5 = readRegister(CONFIG_REG5_ADDRESS);
delayMicroseconds(50);
Config_Reg6 = readRegister(CONFIG_REG6_ADDRESS);
delayMicroseconds(50);
Config_Reg7 = readRegister(CONFIG_REG7_ADDRESS);
delayMicroseconds(50);
Config_Reg8 = readRegister(CONFIG_REG8_ADDRESS);
delayMicroseconds(50);
Config_Reg9 = readRegister(CONFIG_REG9_ADDRESS);
delayMicroseconds(50);
Config_Reg10 = readRegister(CONFIG_REG10_ADDRESS);
delayMicroseconds(50);
delay(100);
Serial.println("Config_Reg : ");
Serial.println(Config_Reg0,HEX);
Serial.println(Config_Reg1,HEX);
Serial.println(Config_Reg2,HEX);
Serial.println(Config_Reg3,HEX);
Serial.println(Config_Reg4,HEX);
Serial.println(Config_Reg5,HEX);
Serial.println(Config_Reg6,HEX);
Serial.println(Config_Reg7,HEX);
Serial.println(Config_Reg8,HEX);
Serial.println(Config_Reg9,HEX);
Serial.println(Config_Reg10,HEX);
Serial.println(" ");
delay(200);
digitalWrite(CS_PIN, HIGH);
}
void loop()
{
delayMicroseconds(50);
delayMicroseconds(50);
long int bit32;
long int bit24;
byte *config_reg;
long int regData;
if((digitalRead(DRDY_PIN)) == LOW) // Wait for DRDY to transition low
{
long int regData;
digitalWrite(CS_PIN, LOW); //Pull SS Low to Enable Communications with ADS1247
delayMicroseconds(10);
// RD: Wait 25ns for ADC12xx to get ready
// SPI.transfer(0x51);
//SPI.transfer(0x00);
// SPI.transfer(0x0F);
// writeRegister(0x01,0x43);
//Issue RDATA
SPI.transfer(SDATAC);
SPI.transfer(SYNC);
SPI.transfer( WAKEUP);
SPI.transfer( RDATAC);
delayMicroseconds(1);
bit24 |= SPI.transfer(NOP);
delayMicroseconds(1);
bit24 <<= 8;
bit24 |= SPI.transfer(NOP);
delayMicroseconds(1);
bit24 <<= 8;
bit24 |= SPI.transfer(NOP);
delayMicroseconds(1);
//Serial.println(regData,HEX);
bit24= ( bit24 << 8 );
bit32 = ( bit24 >> 8 );
// Converting 24 bit two's complement to 32 bit two's complement
delayMicroseconds(10);
//Serial.println(bit24,HEX);
float Vout = (float)((bit32VFSR1000)/FSR); //In mV
delay(300);
Serial.print("Vout in mV : ");
Serial.print(Vout);
Serial.print(" 32bit HEX : ");
Serial.println(bit32,HEX);
}
}
void writeRegister(uint8_t address, uint8_t value)
{
delayMicroseconds(10);
// waitforDRDY();
//SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE1)); // initialize SPI with SPI_SPEED, MSB first, SPI Mode1
digitalWrite(CS_PIN, LOW);
delayMicroseconds(10);
SPI.transfer(WREG | address); // send 1st command byte, address of the register
SPI.transfer(0x00); // send 2nd command byte, write only one register
SPI.transfer(value); // write data (1 Byte) for the register
delayMicroseconds(10);
digitalWrite(CS_PIN, HIGH);
}
uint8_t readRegister(uint8_t address)
{
uint8_t data;
// waitforDRDY();
// SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE1)); // initialize SPI with 4Mhz clock, MSB first, SPI Mode0
digitalWrite(CS_PIN, LOW);
delayMicroseconds(10);
SPI.transfer(RREG | address); // send 1st command byte, address of the register
SPI.transfer(0x00); // send 2nd command byte, read only one register
delayMicroseconds(10);
data = SPI.transfer(NOP); // read data of the register
delayMicroseconds(10);
digitalWrite(CS_PIN, HIGH);
//digitalWrite(_START, LOW);
// SPI.endTransaction();
return data;
}
void waitforDRDY()
{
while (DRDY_state)
{
continue;
}
noInterrupts();
DRDY_state = HIGH;
interrupts();
}
//Interrupt function
void DRDY_Interuppt()
{
DRDY_state = !DRDY_state;
// state = !state;
}
output on serial is
so garbage value is come......
so i not able to understand where i did mistake......