from the datasheet, IMHO there is no need to used SPI with this device.
something like this may work to get the ADC read:
(Compiles, NOT tested!)
#define CS_PIN 7
#define CLK_PIN 8
#define DATA_PIN 9
uint8_t read_ad7478(){
int temp;
digitalWrite(CLK_PIN,LOW);
digitalWrite(CS_PIN,LOW);
for( int i=0; i<2; ++i){ //2 loop since fist data received is unstable according to datasheet
temp = 0;
for( int j=0; j<16; ++j){ //loop to receive ADC value
digitalWrite(CLK_PIN,LOW);
digitalWrite(CLK_PIN,HIGH);
temp = ((temp<<1) | digitalRead(DATA_PIN));
}
}
digitalWrite(CS_PIN,HIGH);
temp >>=4;
return (uint8_t) temp;
}
void setup() {
Serial.begin(115200);
pinMode(DATA_PIN,INPUT_PULLUP);
pinMode(CLK_PIN, OUTPUT);
pinMode(CS_PIN, OUTPUT);
digitalWrite(CS_PIN,HIGH);
Serial.println("AD7478 sample Code");
}
void loop() {
uint8_t adc_val = read_ad7478();
Serial.print("adc value = ");
Serial.println(adc_val);
delay(500); //perform ADC read every 500ms
}
if you keep the CS pin permanently low then you can have 'continuous' ADC in IMHO ie only very first read would need to be rejected and all subsequent ADC read should be valid.
as this is a common habit if somebody posts for the first time to write
"welcome to the arduino-Forum"
having fullfilled this habit I get straight to the point:
To me you gave a pretty negative image of yourself and I want to explain why
you did not read "how to get the best out of this forum
you used "plz" instead of taking the effort of writing "please" in the titel
you posted a code that is below a compilable minimum
you did not post a link to the datasheet of your ADC-chip
you did not post the code as a code-section
you wrote a few poor words
which again shows that you try to minimise your own effort and to maximise the work for your potenttal helpers
Your next answer is
OK at least saying "thank you"
Still using such shortaged words like "u" "sw code" again demonstrates lazyness instead of own effort.
The standard-reaction to such postings is:
no reaction at all
or
a very short - not very helpful - answer with links where you can read up how it is done yourself
english seems not to be your native language. If your english is limited you should use google-translate. Limited english and not using google-translate to me is arrogant
so to change your picture from rather negative to much more positive you should really read and then obey the recommendations given here.
Kindly please check what is the point of using an 8 bit external A/D when the Mega already has many 10 bit A/D converters. The only point in using an external A/D is to get better resolution than you get for free.
Hello
I made a code that can read the data of the ADCS7478 part(I attached it) from Arduino.
I'm still studying because I'm a beginner and I have a lot of room for improvement.
Any advice regarding the code would be appreciated.
#include <SPI.h> // include the SPI library
void setup() {
Serial.begin(9600); //Initalise port to print in serial terminal
SPI.begin();
SPI.setBitOrder(LSBFIRST);
SPI.setDataMode(SPI_MODE3); //CPOL=1, CPHA=1
SPI.setClockDivider(SPI_CLOCK_DIV8); // Sets clock for SPI communication at 8 (16/8=2Mhz)
pinMode(SS,OUTPUT); // Set SPI slave select pin as output
digitalWrite(SS,HIGH); // disable Slave Select
}
void loop() {
digitalWrite(SS,LOW);//Enables SPI
{
byte receivedData=SPI.transfer(0x00); //Send the mastersend value to slave also receives value from slave
Serial.print(receivedData);
}
digitalWrite(SS,high);//Disables SPI
delay(1000); // delay in between reads for stability
void setup() {
Serial.begin(9600); //Initalise port to print in serial terminal
SPI.begin();
SPI.setBitOrder(LSBFIRST);
SPI.setDataMode(SPI_MODE3); //CPOL=1, CPHA=1
SPI.setClockDivider(SPI_CLOCK_DIV8); // Sets clock for SPI communication at 8 (16/8=2Mhz)
pinMode(SS,OUTPUT); // Set SPI slave select pin as output
digitalWrite(SS,HIGH); // disable Slave Select
}
void loop() {
digitalWrite(SS,LOW);//Enables SPI
{
byte receivedData=SPI.transfer(0x00); //Send the mastersend value to slave also receives value from slave
Serial.print(receivedData);
}
digitalWrite(SS,high);//Disables SPI
delay(1000); // delay in between reads for stability
void loop() {
digitalWrite(SS,LOW);//Enables SPI
// { You do not need this brace.
byte receivedData=SPI.transfer(0x00); //Send the mastersend value to slave also receives value from slave
// Serial.print(receivedData);
Serial.println(receivedData);
//} You do not need this brace.
digitalWrite(SS,high);//Disables SPI
delay(1000); // delay in between reads for stability
}
What do you mean by "read data from Arduino Mega", Do you mean you want to capture the output from the print statements?
If so, you can:
Use the Arduino Serial monitor, then copy/paste the content to a text editor.
Use a terminal program with a log to file capability (e.g. putty)
Use a custom program that you write (e.g. in python, C, Java, Processing or heaps more options) read from the serial port and write the data to a file directly.
If you mean something else, please be more clear as to what you mean by "read data from...".
Also, I've modified your code a little:
You won't need the two braces that I have commented out - they add no value and have no effect on the logic of your program.
You probably want println (not print). Otherwise all of your output will be clumped together on a single very long line - e.g. allclumpedtogetheronasingleverylonglinemakingitdifficulttoreadlateron.
Are you hoping to get a second (different?) opinion?
Anyway, here is my reply from the other copy of this post:
void loop() {
digitalWrite(SS,LOW);//Enables SPI
// { You do not need this brace.
byte receivedData=SPI.transfer(0x00); //Send the mastersend value to slave also receives value from slave
// Serial.print(receivedData);
Serial.println(receivedData);
//} You do not need this brace.
digitalWrite(SS,high);//Disables SPI
delay(1000); // delay in between reads for stability
}
What do you mean by "read data from Arduino Mega", Do you mean you want to capture the output from the print statements?
If so, you can:
Use the Arduino Serial monitor, then copy/paste the content to a text editor.
Use a terminal program with a log to file capability (e.g. putty)
Use a custom program that you write (e.g. in python, C, Java, Processing or heaps more options) read from the serial port and write the data to a file directly.
If you mean something else, please be more clear as to what you mean by "read data from...".
Also, I've modified your code a little:
You won't need the two braces that I have commented out - they add no value and have no effect on the logic of your program.
You probably want println (not print). Otherwise all of your output will be clumped together on a single very long line - e.g. allclumpedtogetheronasingleverylonglinemakingitdifficulttoreadlateron.
But you did attach the code not as a code-section.
Read this tutorial how to attach code as a code-section.
and as a general hint:
If you want to speed up finishing your project
now you should really take 20 minutes of your real expensive time where each minute is worth one million dollars
and finally read
```cpp
#include <SPI.h> // include the SPI library
void setup() {
Serial.begin(9600); //Initalise port to print in serial terminal
SPI.begin();
SPI.setBitOrder(LSBFIRST);
SPI.setDataMode(SPI_MODE3); //CPOL=1, CPHA=1
SPI.setClockDivider(SPI_CLOCK_DIV8); // Sets clock for SPI communication at 8 (16/8=2Mhz)
pinMode(SS, OUTPUT); // Set SPI slave select pin as output
digitalWrite(SS, HIGH); // disable Slave Select
}
void loop() {
digitalWrite(SS, LOW); //Enables SPI
byte receivedData = SPI.transfer(0x00); //Send the mastersend value to slave also receives value from slave
Serial.println(receivedData);
digitalWrite(SS, high); //Disables SPI
delay(1000); // delay in between reads for stability
}
hello it is particular application.
It is a system called wireless power transmission to convert analog information containing phase and amplitude information into digital and process the data.
I am planning to do FFT after reading digital 8bit data from ADC in Arduino. Which method would be convenient?
Use the Arduino Serial monitor, then copy/paste the content to a text editor.
Use a terminal program with a log to file capability (e.g. putty)
Use a custom program that you write (e.g. in python, C, Java, Processing or heaps more options) read from the serial port and write the data to a file directly.