Hello, There !
I am working on one of my project; In that i am using 16-bit ADC (ADS8681) and trying to read the data from it with Arduino MEGA using SPI mode. I am able to write the 32-bit data (WRITE Instruction with Data) and getting correct waveform on oscilloscope of which data shared. When i am trying to read the 16-bit data from ADC by applying analog voltage it shows correct variation (Reading the 16-bit data ) but when removed load it shows random value. Is it the problem of reading ADC data? for 32-bit read instruction. Can anyone will give suggestions.
References Which I used:
- SPI library : SPI - Arduino Reference
- SPI Examples : https://www.arduino.cc/en/Tutorial/LibraryExamples/BarometricPressureSensor
- Forum : Send 32 bit SPI request and receive 32 bit response - Networking, Protocols, and Devices - Arduino Forum
Arduino SPI Pins :
- SCK 52
- MOSI 51
- MISO 50
- SS 53
#include <SPI.h>
#include <LiquidCrystal.h>
#define SS 53
uint16_t receivedVal16 = 0 ;
LiquidCrystal lcd (38,37,36,35,34,33);
void setup()
{
lcd.begin(16,4);
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
digitalWrite(SS,OUTPUT);
digitalWrite(SS, HIGH); //Write on REG
delay(10);
digitalWrite(SS,LOW);
SPI.transfer(0xD4);
SPI.transfer(0x14);
SPI.transfer(0x00);
SPI.transfer(0x01);
}
void loop()
{
digitalWrite(SS, HIGH); //Write on Register
delay(10);
digitalWrite(SS,LOW);
SPI.transfer(0xD4); // Write Command
SPI.transfer(0x14); // Reg. Address
SPI.transfer(0x00); // Data
SPI.transfer(0x01); // Data
digitalWrite(SS, HIGH); //Read REG
delay(10);
digitalWrite(SS,LOW);
receivedVal16 = SPI.transfer16(0x0000);
lcd.setCursor(0,1);
lcd.print(receivedVal16);
delay(100);
}