Part Number:ADS1120
#include "ADS1220.h" #include "spi.h" #include "main.h" #include "math.h" #include <stdio.h> #define R_ref 20000 #define ADS1120_MAXCODE 32768 void ADS1220AssertCS(int fAssert) { if (fAssert) CLR_CS1; else SET_CS1; } void ADS1220SendByte(unsigned char Byte) { HAL_SPI_Transmit(&hspi2,&Byte,1,10); } unsigned char ADS1220ReceiveByte() { unsigned char SData = 0xff ,Result = 0; HAL_SPI_TransmitReceive(&hspi2,&SData,&Result,1,10); return Result; } /* ****************************************************************************** higher level functions */ void ADS1220ReadRegister(int StartAddress, int NumRegs, unsigned * pData) {int i; /* assert CS to start transfer */ ADS1220AssertCS(1); /* send the command byte */ ADS1220SendByte(ADS1220_CMD_RREG | (((StartAddress<<2) & 0x0c) |((NumRegs-1)&0x03))); /* get the register content */ for (i=0; i< NumRegs; i++) { *pData++ = ADS1220ReceiveByte(); } /* de-assert CS */ ADS1220AssertCS(0); return; } void ADS1220WriteRegister(int StartAddress, int NumRegs, unsigned char * pData) { int i; /* assert CS to start transfer */ ADS1220AssertCS(1); /* send the command byte */ ADS1220SendByte(ADS1220_CMD_WREG | (((StartAddress<<2) & 0x0c) |((NumRegs-1)&0x03)));/* send the data bytes */ for (i=0; i< NumRegs; i++) { ADS1220SendByte(*pData++); } /* de-assert CS */ // HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET); ADS1220AssertCS(0); return; } void ADS1220SendResetCommand() { /* assert CS to start transfer */ ADS1220AssertCS(1); /* send the command byte */ ADS1220SendByte(ADS1220_CMD_RESET); /* de-assert CS */ ADS1220AssertCS(0); return; } void ADS1220SendStartCommand() { /* assert CS to start transfer */ ADS1220AssertCS(1);/* send the command byte */ ADS1220SendByte(ADS1220_CMD_SYNC); /* de-assert CS */ ADS1220AssertCS(0);return; } void ADS1220SendShutdownCommand() { /* assert CS to start transfer */ ADS1220AssertCS(1); /* send the command byte */ ADS1220SendByte(ADS1220_CMD_SHUTDOWN); /* de-assert CS */ ADS1220AssertCS(0);return; } /* ADS1220 Initial Configuration */ void ADS1220Init(void) { uint8_t ch_cfg[4]={ADS1220_MUX_1_0|ADS1220_GAIN_1|ADS1220_PGA_BYPASS, ADS1220_CC|ADS1220_DR_1000, ADS1220_VREF_EX_DED|ADS1220_PSW_SW|ADS1220_IDAC_100|ADS1220_REJECT_BOTH, ADS1220_IDAC1_AIN3|ADS1220_IDAC2_OFF|ADS1220_DRDY_MODE}; // uint8_t ch_cfg[4]={ADS1220_MUX_0_G|ADS1220_GAIN_1|ADS1220_PGA_BYPASS, ADS1220_CC|ADS1220_DR_20, ADS1220_VREF_INT|ADS1220_PSW_SW|ADS1220_IDAC_OFF, ADS1220_IDAC1_OFF|ADS1220_IDAC2_OFF}; ADS1220SendResetCommand();//¸´Î»HAL_Delay(100); ADS1220WriteRegister(ADS1220_0_REGISTER,4,ch_cfg);//ÅäÖÃ4¸ö¼Ä´æÆ÷ HAL_Delay(100); ADS1220SendStartCommand(); } long ADS1220ReadData() { long Data; // unsigned int cfg[4]; /* assert CS to start transfer */ ADS1220AssertCS(1); /* send the command byte */ADS1220SendByte(ADS1220_CMD_RDATA); /* get the conversion result */ //#ifdef ADS1120 // ADS1220ReadRegister(ADS1220_0_REGISTER,4,cfg); Data = ADS1220ReceiveByte(); Data = (Data<<8) | ADS1220ReceiveByte(); /* sign extend data */ // if (Data & 0x8000) // Data |= 0xffff0000; //#else // Data = ADS1220ReceiveByte(); // Data = (Data << 8) | ADS1220ReceiveByte(); ////Data = (Data << 8) | ADS1220ReceiveByte(); // /* sign extend data */ // if (Data & 0x8000) // Data |= 0xffff0000; //#endif /* de-assert CS */ ADS1220AssertCS(0); return Data; }
当按照原理图和代码配置完成后,并没有电流源的输出,而且测不到准确的代码,一直在变动
Amy Luo:
您好,
“没有电流源的输出”,这很可能是寄存器没有按期望值写入,建议您先验证寄存器写入后可以正确读出写入值,最好的检查方法是使用示波器或逻辑分析仪抓取SPI通信波形,看SPI通信时序是否正确或通信波形上是否存在干扰?
,
sq l:
所有寄存器在配置后,都使用了读寄存器函数 ,发现其读出来的数和我配置的一样
但是在示波器抓取SPI波形时,一个CS周期内有8个字节的SCK信号 请问是怎么回事
,
Amy Luo:
ADS1120的4个寄存器分别配置的是什么?您是怎样确定没有电流源输出的?
sq l 说:但是在示波器抓取SPI波形时,一个CS周期内有8个字节的SCK信号 请问是怎么回事
此时进行的操作是什么?是读取转换结果还是读或写寄存器?
,
sq l:
配置为输出电流为100uA 在AIN3引脚输出 ,请问一下这个电流输出的话 是一个持续输出还是短暂瞬间输出,并且这个芯片如果损坏了 能检测出来吗
,
sq l:
四个寄存器分别配置为 61 04 5B 82,原理图中 当配置完后 电流有输出的情况下 那个参考电阻 20K的两端应该有2V的电压,但是实际中测不到 为0V
,
Amy Luo:
如果寄存器配置有输出且不改变的话,IDAC电流是一直有输出的。
如果芯片损坏了不能输出电流了,那就检测不出来了。
看寄存器配置没问题,测试参考电阻20K两端电压时,NTC是否正确连接了?IDAC电流是通过NTC传感器流入到20K参考电阻的,如果NTC连接没有给IDAC电流形成回路,那测电阻两端也是测不出来的。
如果怀疑芯片损坏,那换一块板子或换一片 ADS1120,使用相同的寄存器配置,是否可以测到电压?