您好,
我正在尝试使用Arduino板配置我的ADS1218。 我正在使用以下设置:
AVCC = 5伏
单极
1920年的小数
数字滤波器SINC3
我在缓冲器关闭的情况下执行校准,并在校准后将其打开。
我正在通过将MUX设置为0x01,FMOD = 9600 Hz,在通道Ain0和Ain1上应用1.3 Vdc
问题是校准后,无论 输入如何,我都会一直读取0.00 ,其电压范围为0至2伏。
如果我在没有校准的情况下使用它,无论输入如何,我都始终获得2.5 V,输入电压范围从0到2伏不等。
这是我的代码:
/**************************************************************
Aalto_ADS1218.ino
此示例提供了通过
Arduino
|ADS1218引脚标签|引脚功能进行UV连接时AN0和AN1之间的差分电压 |Arduino Connection|
|----------- |:----------- :|----------- :||DRDY
|数据就绪输出引脚| D6. |
|味增 |从机输出 | D12. |
| MOSI |从机进入 | D11. |
| SCLK. |串行时钟 | D13. |
| CS |芯片选择 | D7. |
| DVDD |数字VDD |+5V |
| DGND |数字接地 | GND |
| AN0-AN3 |模拟输入 |模拟输入|
| AVDD |模拟VDD |- |
| AGND |模拟接地 |- **********
/
#include <SPI.h>
#define SPI_MASTER_DUMMY 0xff
#define reset 0x06 //发送reset命令(06h)以确保在通电后正确重置ADS1220
#define start 0x08 //发送启动/同步命令(08h)以在连续转换模式下开始转换
//定义ads1218命令
#define RDATA 0x01 //读取最新的AD转换数据
#define RDATAC 0x03 //连续读取转换的数据
#define STOPC 0x0F //停止连续读取模式
#define RREG 0x10 //用于读取寄存器内容的双字节命令第一个字节:BIT3-bit0 = 0-16;
#define RRAM 0x20 //用于读取第一个字节RAM内容的双字节命令:BIT3-bit0 = 0-16;
#define CREG 0x40 //将寄存器的内容复制到指定的ram bank中,下面三位指定ram页地址
#define CREGA 0x48 //将寄存器的内容复制到所有ram bank中。
#Define WREG 0x50 // 2字节命令,将数据写入寄存器0-15#define
WRAM 0x60 // 2字节指令,将数据写入RAM中的128字节
#define RF2R 0x80 //将指定闪存页的数据读取为128字节的RAM
#define WR2F 0xA0 //将ram中的数据写入指定的闪存页
#define cram 0xC0 //将选定的ram数据复制到配置寄存器中,这将覆盖当前工作寄存器内容
#define CRAMX 0xD0 //在指定的页ram中计算校验和,不包括ID,DRDY DIO
#define CSARAMX 0xD8 //在所有ram中计算校验和,不包括ID, DRDY DIO
#define CSARAM 0xDF //计算配置寄存器的校验和
#define CSRAM 0xE0 //计算指定页面RAM中的校验和,其中包含所有位
#define CSARAM 0xE8 //计算所有RAM中的校验和,其中包含所有位
#define CFL 0xEC //计算所有闪存中的校验和, 包括所有位
#define SCLFCAL 0xF0 //偏移和增益自校准
#define SELFOCAL 0xF1 //偏移自校准
#define SCLFGCAL 0xF2 //增益自校准
#define SYSOCAL 0xF3 //系统偏移校准
#define SYSGCAL0xF4 //系统增益校准
#define DSYNC 0xFC //同步DRDY
#define睡眠模式0xFD
重置0xFE //将寄存器重置为数据的功率,停止连续读取模式, 不影响ram数据
//定义ads1218寄存器地址
#define SETUP_REG_ADRS 0x00
#define MUX_REG_ADRS 0x01
#define ACR_REG_ADRS 0x02
#define IDAC1_REG_AD0x03
#define IDAC2_REG_ADRs_ADREG_ADRs_0x014_ADRs_define #AD0014_ADRs_0x014_ADRs_DEFAST_ADRs_DEF014_AD014_AD014_ADRs_DEF_AD014_AD014_AD014_ADRs_DEFAE #014_AD014_AD014_ADRs_DEFAE #014_AD0_AD014_AD014_AD014_ADRs_DEFAE
0x0C
#define FSR0_REG_ADRS 0x0D
#define FSR1_REG_ADRS 0x0E
#define FSR2_REG_ADRS 0x0F
#define ADS1218_CS_PIN 7
#define ADS1218_DRDY_PIN 6
void writeRegister (uint8_t地址,uint8_t值)
{ uint8_microrep
;
PIN码= 1218_microrep;0
= 12秒;数;数;0
SPI.transfer (WREG |地址);
SPI.transfer (numReg);
SPI.transfer (value);
// delayMicroseconds (500);
digitalWrite (ADS1218_CS_PIN, high);
interrupts();
}
uint8_t readRegister (uint8_t地址)
{
uint8_t data;
uint8_t numReg = 0x01;
noInterrupts();
digitalWrite(ASD1218_CS_PIN, low);
// delayMicroseconds(500);
SPI.transfer (REG |地址);
SPI.transfer (numReg);
delayMicroseconds (20); //所需10 us
数据的延迟= SPI.transfer (SPI_MASTER_DUMMY);
// delayMicroseconds(500);
digitalWrite(ASD1218_CS_PIN, HIGH );
Interrupts();
返回数据;
}
void printAllreg(void)
{
int read_Data0;
for (int i =0;i <=15;I++){
READ_Data0 = readRegister (i);
serial.println (read_Data0,hex);
Delay(10);
}
void SendSELFCALCommand(void)
{
noInterrupts();
digitalWrite(ASD1218_CS_PIN, low);
delayMicroseconds(500);
SPI.transfer(SELFCAL);
delayMicroseconds(500);
digitalWrite(ASD1218_CS_PIN, high );
interrups();delay(2000);
}
void synsyncSerialData(void){
noInterrupts();
digitalWrite(ASD1218_CS_PIN, low);
delayMicroseconds(500);
SPI.transfer(DSYNC);
delayMicroseconds(500);
digitalWrite(ASD1218_CS_PIN, high );
interrupts();
delay(2000);
}
void waitForDataReady(int timeout)//等待数据就绪
{//
等待/DRDY =1
等待((digitalRead(ADS1218_DRDY_PIN))!=低);//
等待/DRDY = 0
等待((INTdigRead(ASD1218_DRDY_PIN))=低);}
UdataForbet=0 (INT_DataFlag)
noInterrupts();
DigitalWrite (ADS1218_CS_PIN,低); //降低CS
// delayMicroseconds(500);
SPI.transfer (RDATA);
DelayMicroseconds(20);
字节msbData = SPI.transfer (SPI_MASTER_DUPY);
字节中间数据= SPI.transfer (SPI_MASTER_DUPY);
字节lsbData = SPI.transfer (SPI_MASTER_DUPY);
// delayMicroseconds(500);
DigitalWrite (ADS1218_CS_PIN,高); //清除CS至高
中断();
dataBits = msbData;
dataBits =(dataBits <<8)| midData;
dataBits =(dataBits <<8)| lsbData;
}
返回dataBits;
}
void setup()
{
digitalWrite(ASD1218_CS_PIN, high );
pinMode(ADS1218_CS_PIN, output);
Serial.begin(9600); //11.52万 5.76万
SPI.begin(); //唤醒SPI总线。
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE1);
SPI.setClockDivider(SPI_CLOCK_DIV64);
writeRegister (0x00,0xFC); //0000 1100,缓冲区已禁用。
DELAY (50);
writeRegister (0x08,0x80);// decimation寄存器1,DEC0
DELAY (50);
writeRegister (0x09,0x77);// decimation寄存器2,Dec1,单极,SINC3过滤器集
延迟(50);
printAllreg();
DELAY (5000);
SendLFC5000命令
writeRegister (0x00, 0xFE);//0000 01110,缓冲区已启用,fmod = 9600
delay(50);
writeRegister (0x08, 0x80);// decimation寄存器1,DEC0
delay(50);
writeRegister (0x09, 0x77);//
同步寄存器2,Dec1,单极,SINUX过滤器集1,串行延迟(50/);数据集x01; xedge();xreach( x01)
void loop()
{
UINT32_t data32=0;
data32 = read_Data(1);
float值=(FLOW(data32)* 2.5 * 100万)/16777216;1677.7216万;
Serial.print("
}bin:");Serial.println(data32, bin); Serial.print("值:");Serial.bin(图
解:32位)

有什么建议???
提前感谢!
Tanweer

