总共多买了两个芯片,所以制作了两块板子。
实物如上,目前Arduino下没有好的驱动,所以我通过SPI写了一个简单的。
如下:
#include <SPI.h>
#define VSPI_MISO MISO
#define VSPI_MOSI MOSI
#define VSPI_SCLK SCK
#define VSPI_SS SS
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
#define VSPI FSPI
#endif
static const int spiClk = 1000000; // 1 MHz
//uninitalised pointers to SPI objects
SPIClass * vspi = NULL;
uint16_t Manual_Mode = 1840;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println(F("Hello! Feather AD7950 Test"));
vspi = new SPIClass(VSPI);
vspi->begin();
pinMode(9, OUTPUT); //VSPI SS
}
void loop() {
// put your main code here, to run repeatedly:
uint16_t adc_data;
uint8_t adc_channel;
float adc_Data;
spi_data_16(vspi, Manual_Mode);
spi_data_16(vspi, Manual_Mode);
adc_data = spi_data_16(vspi, Manual_Mode);
Serial.println(adc_data);
Serial.print("adc_channel:");
adc_channel = adc_data >> 12;
Serial.println(adc_channel);
Serial.print("adc_data:");
adc_Data = ((adc_data&0x0fff)/4095.0)*2.5;
Serial.println(adc_Data);
delay(1000);
}
uint8_t spi_data(SPIClass *spi, uint8_t data)
{
uint8_t receive_data;
spi->beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE1));
receive_data = spi->transfer(data);
spi->endTransaction();
return receive_data;
}
uint16_t spi_data_16(SPIClass *spi, uint16_t data)
{
uint16_t receive_data;
spi->beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE1));
digitalWrite(9, LOW); //pull SS slow to prep other end for transfer
receive_data = spi->transfer16(data);
digitalWrite(9, HIGH); //pull ss high to signify end of data transfer
spi->endTransaction();
return receive_data;
}
此芯片是有三种模式的,所以我就配置了一种,还有就是其输入和采集有两倍关系没看到手册在哪配置。
测试效果如下:
输入超量程就会出现问题,在0-1.25V内输入都是两倍的关系,还挺稳定的。