Other Parts Discussed in Thread: REF6025
Dear TI support team,
I am trying to interface ADS8321 16 bit ADC from TI with Teensy 3.5 (Arduino compatible platform MCU). (Vin- = 2.5V, Vref=2.5V and Vin+ is voltage input).
The ADC is supplied with 5V, while Teensy is at 3.3V. I checked the datasheet and İnput high and low levels are ok with teensy logic levels. Also, teensy input are ok with ADC output. I have made the communication as stated in the datasheet. The problem is I cannot get stable results. For example, when I am trying to read 3.3V level with ADC, it shows different and wrong values. The value I get from ADC is not same, although the einput voltage (for example 3.3V) is always same. The ADC is on PCB and Teensy is also on same pcb, they are connected with PCB track. I checked the wiring it was also correct.
I am not using SPI in the code. I am just making bit banging. For SPI part I donot know how to implement SPI by looking at device datasheet. If possible could you please provide some pseudo code for SPI communication (what to send via SPI etc).
I am attaching my code and wiring diagram. Could you please help me to solve the issue?
Thank you for your help.
Ahmet
//ADS8321 current measurement, ADC 16 bit const int clock_pin = 3; const int data_pin = 4; const int cs_pin = 5; void setup () { pinMode(clock_pin, OUTPUT); pinMode(data_pin, INPUT); pinMode(cs_pin, OUTPUT); } void loop() { float m = readADC(); Serial.println(m); delay(1000); } float readADC() { int16_t adcvalue = 0; digitalWrite(cs_pin, LOW); //Select ADC for (int i = 0; i < 6; i++) { digitalWrite(clock_pin, HIGH); // 6 clock cycles for sampling //delayMicroseconds(5); digitalWrite(clock_pin, LOW); //delayMicroseconds(5); } //read bits from adc, //16 clock for data reading for (int i = 16; i > 0; i--) { // 16 for reading //cycle clock digitalWrite(clock_pin, HIGH); // make clock high adcvalue |= digitalRead(data_pin) << i; // Read data bit digitalWrite(clock_pin, LOW); // make clock low } float a; a=(adcvalue+32768)*5/65536; // convert to 0-5V range digitalWrite(cs_pin,HIGH); //turn off device return a; }