This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello sir/maa'm,
Actually I want to interface the ADS124S08 ADC with my arduino UNO. So first I have have disabled the TIVA processor by shorting JP1 jumper, now I have connected the hardware side SPI pins at J3 with arduino UNO and my input side hardware is strain guage at J8 configuration
SCLK =13;
MOSI =11;
MISO=12;
START=6;
RESET=7;
CS=4;
The code is given below
Hi Bob,
Thank you for your explanation. Actually I have changed my code also,as you said about my unending for loop that is my mistake,that also I changed. And also I have given the delay after RDATA command. But when I have uploaded the code on arduino, I observed on serial monitor that only 3 digit data is coming and our ADC is 24 bit so it should range from 0 to 2^23 but data is coming between 0 to 255. My code is as follows:
#include <SPI.h>
#include <TimerOne.h>
#define START 6
#define RESET 7
const int CS = 4;
int stat;
int stat1;
int stat2;
SPISettings settings1(4000000, MSBFIRST, SPI_MODE1);
void setup() {
SPI.begin();
pinMode(CS,OUTPUT);
pinMode(RESET, OUTPUT);
pinMode(START,OUTPUT);
digitalWrite(RESET , HIGH);
delay(1000);
Serial.begin(9600);
SPI.beginTransaction(settings1);
digitalWrite(CS, LOW);
digitalWrite(START,LOW);
}
void loop() {
for(int i=0;i<=5;i++)
{
if(i==0){
SPI.transfer(0x42); // WREG register adress
SPI.transfer(0x02); // WREG byte number -1
SPI.transfer(0x24); // WREG write AIN2-AIN4
SPI.transfer(0x07); 128 gain
SPI.transfer(0x1E); // DATA RATE 4000 SPS
SPI.transfer(0x12); //RDATA command
delayMicroseconds(1000);
}
else
{
SPI.transfer(0x08); // start converting command
stat = SPI.transfer(0) ; // get data from miso
Serial.println(stat);
}
}
SPI.endTransaction();
}
Hi Sushmita,
See my comments below. It appears that you have the RDATA and START commands swapped. You also need to make sure that you wait for each conversion to be competed before reading the results.
Best regards,
Bob B
Sushmita Chaudhary said:Hi Bob,
Thank you for your explanation. Actually I have changed my code also,as you said about my unending for loop that is my mistake,that also I changed. And also I have given the delay after RDATA command. But when I have uploaded the code on arduino, I observed on serial monitor that only 3 digit data is coming and our ADC is 24 bit so it should range from 0 to 2^23 but data is coming between 0 to 255. My code is as follows:
#include <SPI.h>
#include <TimerOne.h>
#define START 6
#define RESET 7
const int CS = 4;
int stat;
int stat1;
int stat2;
SPISettings settings1(4000000, MSBFIRST, SPI_MODE1);
void setup() {
SPI.begin();
pinMode(CS,OUTPUT);
pinMode(RESET, OUTPUT);
pinMode(START,OUTPUT);
digitalWrite(RESET , HIGH);
delay(1000); // [Bob] This delay must be long enough for the device to start prior to beginning any communication if delay refers to 1ms per count, then the delay will be sufficient.
Serial.begin(9600);
SPI.beginTransaction(settings1);
digitalWrite(CS, LOW);
digitalWrite(START,LOW);
}
void loop() {
for(int i=0;i<=5;i++)
{
if(i==0){
SPI.transfer(0x42); // WREG register adress
SPI.transfer(0x02); // WREG byte number -1
SPI.transfer(0x24); // WREG write AIN2-AIN4
SPI.transfer(0x07); 128 gain
SPI.transfer(0x1E); // DATA RATE 4000 SPS
SPI.transfer(0x12); //RDATA command [Bob] this command is meaningless for two reasons. One is no conversion has yet taken place and the second reason is the command was not completed. RDATA is a command to be followed by 3-bytes of data read from the device. What should have been sent here should have been the START command (0x08) to start a conversion. The command here should be:
SPI.transfer(0x08); // start converting command
delayMicroseconds(1000);
}
else
{
SPI.transfer(0x08); // start converting command [Bob] Here you start the conversion but give no time for the conversion to complete, so at this point any data read from the device will be meaningless. Here you should have issued the RDATA command to read the data, followed by 3 bytes of NOPs to retrieve the data. So you have the START and RDATA commands swapped in the code. Also, as you are not using CS the previous command was not completed so this is actually the first retrieval byte of the RDATA command. When holding CS low you should use the SPI timeout feature which is enabled by setting the TIMEOUT bit to 1 in the system control register (0x09). This will allow an incomplete command to be canceled resetting the SPI interface after the timeout period (section 9.5.1.6 on page 63 of the ADS124S08 datasheet.)
The command should be:
SPI.transfer(0x12); //RDATA command
stat = SPI.transfer(0) ; // get data from miso [Bob] The original RDATA command was still incomplete, so this would actually be the middle byte of 3 from the ADS124S08. The remaining portions of the command should be:
stat = (stat<<8) | SPI.transfer(0); // Using the RDATA command the first save to stat is the MSB, and this is the mid-byte
stat = (stat<<8) | SPI.transfer(0); // Using the RDATA command the save to stat includes the LSB, which is now 24 bits of 32...now you need sign-extension for negative values.
// Add sign-extension code here to achieve negative values
Serial.println(stat); // [Bob] As you are only capturing 1 byte in your original code you are only transferring one byte. As 'stat' is declared as an integer, you must also sign-extend the 24 bit binary 2's complement result to 32 bits.
delayMicroseconds(250); // [Bob] You will also need an additional delay to allow the next conversion period to end.
}
}
SPI.endTransaction();
}
Hi Bob,
Thanks for your great help.
I have made the changes as you suggested but instead of changing CS bit during conversion,I made the timeout bit 1 so it will take care when I am putting CS bit permanently low.
I am getting full scale reading that is 2 complement (8388607, that is 7FFFFF in hexa) but when I am putting the load on my skin friction sensor my output remains that full scale value it is not changing as the load is changing.
Regards
Sushmita
Hi Sushmita,
Can you send me your schematic? Can you verify that DRDY is toggling and signaling the end of conversion? Can you tell me what you are using for a reference? And what are your configuration register settings?
Thanks,
Bob B
Hi Bob,
My code is as follows,
#include <SPI.h>
#include <TimerOne.h>
#define START 6
#define RESET 7
#define CS 4
long signed int stat;
SPISettings settings1(4000000, MSBFIRST, SPI_MODE1);
void setup() {
SPI.begin();
pinMode(CS,OUTPUT);
pinMode(RESET, OUTPUT);
pinMode(START,OUTPUT);
digitalWrite(RESET , HIGH);
delay(5); //
Serial.begin(9600);
SPI.beginTransaction(settings1);
digitalWrite(CS, LOW);
digitalWrite(START,LOW);
}
void loop() {
for(int i=0;i<10;i++)
{
if(i==0){
SPI.transfer(0x42); // WREG register adress
SPI.transfer(0x07); // WREG byte number -1
SPI.transfer(0x24); // WREG write AIN2-AIN4
SPI.transfer(0x07); //128 gain
SPI.transfer(0x1E); // DATA RATE 4000 SPS
SPI.transfer(0x10); //REF
SPI.transfer(0x00); // IDAC MAG
SPI.transfer(0xFF); // IDAC MUX
SPI.transfer(0x00);// Vbias
SPI.transfer(0x14);// Timeout bit second =1 ,default is 10h
SPI.transfer(0x08); // start converting command
delay(1);
}
else
{
SPI.transfer(0x12); //RDATA command
stat = SPI.transfer(0) ;
stat = (stat<<8) | SPI.transfer(0);
stat = (stat<<8) | SPI.transfer(0);
Serial.print(stat);
Serial.print("\n");
delayMicroseconds(250);// need an additional delay to allow the next conversion period to end.
}
//digitalWrite(CS,HIGH);
}
SPI.endTransaction();
}
But DRDY pin is not necessary for conversion that's why I have not included in code.
Hi Sushmita,
Your code appears to be ok, however in some way you need to verify your communication and that the device is operating. Using an oscilloscope or logic analyzer will help you to determine if you are communicating correctly. You cannot short-cut this step. Please send me shots of your communication. Check DRDY with an scope or analyzer to make sure that it is pulsing at the data rate you have programmed to the device. If it is not, then you are either missing a supply, a required pin setting is not as it should be (possible wiring issue), or you are not communicating to the device properly.
Best regards,
Bob B
Hi Bob,
Sometimes the data will vary and sometimes it shows full scale reading,may be the problem is in connection and how we will ensure that particular digital value is right or not?
Tomorrow I will send you the oscilloscope graphs.
Thanks
Regards
Sushmita