Hello everyone,
i'm new in Arduino world, i have a project where i have to receive data from the ADC7476 using SPI connection, the problem is when i use Serial.println(12), the clock and cs stops, when i comment that line they start working again, i'm using an Arduino Uno R3, here is the datasheet for this 12 bits adc http://www.ti.com/lit/ds/symlink/adcs7476.pdf, i connected it with:
Pin 10 (cs)
DATAIN 12//MISO
CLOCK 13//Clock
here is my program:
#include<SPI.h> #define cs 10
SPISettings settingsA(250000, MSBFIRST, SPI_MODE0);
int incomingData;
int junk=0xFF;
void setup() {
Serial.begin(9600);
pinMode(cs, OUTPUT);
digitalWrite(cs, HIGH);
delay(1000);
SPI.begin();
}
when i comment the serial.println() the clock and cs works fine but when i remove the comment (//) they stop working so the adc can't work, so now i don't know how to receive Data from the Adc7476 i tried Serial.println(12,BIN) then Serial.println(incomingData) without success so i wonder what am i suposed to have in incomingData?
This code, with the Serial.println() commented or uncommented makes NO sense.
The digitalRead() function takes a pin number, and returns a value. If you don't care what the value is, it is a complete waste of effort to read the value.
Do NOT try to print stuff between SPI.beginTransaction() and SPI.endTransaction(). Save the data, in an array if there is more than one byte, and print the data AFTER ending the transaction.
hey thank you for your response,
emm could you please correct the program so i can receive the conversion result from the adc, i connected it with the miso which is pin 12, i really don't know how to save this data in array like you said, by the way i should get 16 bits where the four first bits are zeros.
No. That is your job. Deleting useless crap is not rocket science.
If you expect to read 16 bits, you'll do that 8 bits at a time. I suspect that you can divide 16 by 8 to figure out how many times you need to call SPI.transfer().
Storing the result from the first call in a variable that indicates that it is the high order byte isn't that difficult.
Storing the result from the second call in a variable that indicates that it is the low order byte isn't that difficult.
(Oops, I gave away how many times you need to call SPI.transfer.)
Combining the high order byte and the low order byte into an int is not difficult.
i know it is my job, thanks for your answer, i like to know how to read the data from the adc, am i right by writing " incomingData = SPI.transfer(junk);"?
just one other thing, to see the conversion result in my computer screen by serial monitor i shouldn't use Serial.println(data)? it is the only way i know to show data in my screen .
because you said :"This code, with the Serial.println() commented or uncommented makes NO sense."
here is my new program:
just one other thing, to see the conversion result in my computer screen by serial monitor i shouldn't use Serial.println(data)? it is the only way i know to show data in my screen .
It is. I didn't say not to use Serial.println(). I said not to use it in the middle of a transaction.
the smiley face wasn't my intention it was written because there were an 8 next to a ")"
it is the same problem when i wrote "Serial.println(data);" there is a problem with the clock and cs like before :(, i read somewhere that if serial.println() doesn't get a value to print, the program may stop working, that what i think is happening, the serial monitor showed the value "0".
here is what the oscilloscope shows before commenting the serial.print(data) then when commenting it
in yelow it's the clock signal , in pink it's de cs: