上边是原理图,芯片一直没有恒流源的输出,转换标志DRDY脚的电平变化正常,但是数据跳动幅度较大。VCC和VCC_A不是同一个电源供电,都是3.3V。START脚接高电平,CLK引脚接地。请用过的朋友帮助看一下,因为恒流源设置的是1毫安电流,参考电阻正常应该有1.6V左右的电压,但是一直测不到电压,是电路有问题导致的芯片没有工作吗,着实弄不懂了。
附上我的代码:
ads1247.h#ifndef __ADS1247_H#define __ADS1247_H#ifdef __cplusplus extern "C" {#endif/* Includes ------------------------------------------------------------------*/#include "main.h"#include "gpio.h" /******************ads1247管脚与MCUSTM32F722对应关系**********SCK(SPI2_SCK)-----------PB13MISO(SPI2_MISO)---------PB14MOSI(SPI2_MOSI)---------PB15 (SPI2)NSS1(ADS_CS1)-----------PC0NSS2(ADS_CS2)-----------PC2NSS3(ADS_CS3)-----------PA4NSS4(ADS_CS4)-----------PA6NSS5(ADS_CS5)-----------PB0NSS6(ADS_CS6)-----------PB12DRDY1(PC1)---------PC1DRDY2(PC3)---------PC3DRDY3(PA5)---------PA5DRDY4(PA7)---------PA7DRDY5(PB1)---------PB1DRDY6(PB2)---------PB2******************ads1247管脚与MCU对应关系*******************///定义引脚有关宏函数#define ADS_NSS1(n) (n?HAL_GPIO_WritePin(GPIOC,SPI2_NSS1_Pin,GPIO_PIN_SET):HAL_GPIO_WritePin(GPIOC,SPI2_NSS1_Pin,GPIO_PIN_RESET))#define ADS_NSS2(n) (n?HAL_GPIO_WritePin(GPIOC,SPI2_NSS2_Pin,GPIO_PIN_SET):HAL_GPIO_WritePin(GPIOC,SPI2_NSS2_Pin,GPIO_PIN_RESET))#define ADS_NSS3(n) (n?HAL_GPIO_WritePin(GPIOA,SPI2_NSS3_Pin,GPIO_PIN_SET):HAL_GPIO_WritePin(GPIOA,SPI2_NSS3_Pin,GPIO_PIN_RESET))#define ADS_NSS4(n) (n?HAL_GPIO_WritePin(GPIOA,SPI2_NSS4_Pin,GPIO_PIN_SET):HAL_GPIO_WritePin(GPIOA,SPI2_NSS4_Pin,GPIO_PIN_RESET))#define ADS_NSS5(n) (n?HAL_GPIO_WritePin(GPIOB,SPI2_NSS5_Pin,GPIO_PIN_SET):HAL_GPIO_WritePin(GPIOB,SPI2_NSS5_Pin,GPIO_PIN_RESET))#define ADS_NSS6(n) (n?HAL_GPIO_WritePin(GPIOB,SPI2_NSS6_Pin,GPIO_PIN_SET):HAL_GPIO_WritePin(GPIOB,SPI2_NSS6_Pin,GPIO_PIN_RESET))#define ADS_RDY6 HAL_GPIO_ReadPin( GPIOC,temp_RDY6_Pin )/******************ads1247寄存器地址*******************/ #define ADS1247_CMD_WAKEUP 0x00//退出睡眠模式 #define ADS1247_CMD_SLEEP 0x02//进入睡眠模式 #define ADS1247_CMD_SYNC 0x04//同步A/D转换 #define ADS1247_CMD_RESET 0x06//上电复位值 #define ADS1247_CMD_NOP 0xff//空操作 #define ADS1247_CMD_RDATA 0x12//读一次数据 #define ADS1247_CMD_RDATAC 0x14//连续读取数据 #define ADS1247_CMD_SDATAC 0x16//停止连续读取数据 #define ADS1247_CMD_RREG 0x20//读寄存器 #define ADS1247_CMD_WREG 0x40//写寄存器 #define ADS1247_CMD_SYSOCAL 0x60//系统偏移校准 #define ADS1247_CMD_SYSGCAL 0x61//系统增益校准 #define ADS1247_CMD_SELFOCAL 0x62//自偏置校准 #define ADS1247_REG_MUX0 0x00//多路复用器控制寄存器0 #define ADS1247_REG_VBIAS 0x01//偏置电压寄存器 #define ADS1247_REG_MUX1 0x02//多路复用器控制寄存器1 #define ADS1247_REG_SYS0 0x03//系统控制寄存器 #define ADS1247_REG_CFC0 0x04//漂移校准系数寄存器0 #define ADS1247_REG_CFC1 0x05//漂移校准系数寄存器1 #define ADS1247_REG_CFC2 0x06//漂移校准系数寄存器2 #define ADS1247_REG_FSC0 0x07//满量程标准系数寄存器0 #define ADS1247_REG_FSC1 0x08//满量程标准系数寄存器1 #define ADS1247_REG_FSC2 0x09//满量程标准系数寄存器2 #define ADS1247_REG_IDAC0 0x0a//IDAC控制寄存器0 #define ADS1247_REG_IDAC1 0x0b//IDAC控制寄存器1 #define ADS1247_REG_GPIOCFG 0x0c//GPIO配置寄存器 #define ADS1247_REG_GPIODIR 0x0d//GPIO方向寄存器 #define ADS1247_REG_GPIODAT 0x0e//GPIO数据寄存器/******************ads1247寄存器地址*******************///ADS1247支持的增益列表 #define ADC_GAIN_1 0x00 #define ADC_GAIN_2 0x10 #define ADC_GAIN_4 0x20 #define ADC_GAIN_8 0x30 #define ADC_GAIN_16 0x40 #define ADC_GAIN_32 0x50 #define ADC_GAIN_64 0x60 #define ADC_GAIN_128 0x70 //ADS1248支持的转换速率列表 #define ADC_SPS_5 0x00 #define ADC_SPS_10 0x01 #define ADC_SPS_20 0x02 #define ADC_SPS_40 0x03 #define ADC_SPS_80 0x04 #define ADC_SPS_160 0x05 #define ADC_SPS_320 0x06 #define ADC_SPS_640 0x07 #define ADC_SPS_1000 0x08 #define ADC_SPS_2000 0x09//ADS124用于计算温度的参数#define RREF 820.0f //参考电阻阻值REREF#define RNOMINAL 100.0f //阻值R0#define RTD_A 3.9083e-3 //IEC751规定#define RTD_B -5.775e-7 //IEC751规定//错误代码#define ADS1247_OK ((uint8_t)0x00)#define ADS1247_ERROR ((uint8_t)0x01)#define ADS1247_BUSY ((uint8_t)0x02)#define ADS1247_tiMEOUT ((uint8_t)0x03)//函数定义,供主函数调用void ADS1247_Init(void); void ADS1247_WriteReg(uint8_t RegAddr,uint8_t *Buffer,uint8_t Length); void ADS1247_ReadReg(uint8_t RegAddr,uint8_t *Buffer,uint8_t Length);uint32_t ADS1247_ReadData_RTD(void);float ADS1247_GetTempture(float *ReadTemp);/* USER CODE END Prototypes */#ifdef __cplusplus}#endif#endif /*__ spi_H */ ads1247.c#include "ADS1247.h"#include "spi.h"#include "math.h"#include "stdio.h"/******************************************************************************* * Function Name : ADS1247_WriteCmd* Description : 向外设1247写命令* Input : Cmd * Output : *******************************************************************************/ static void ADS1247_WriteCmd(uint8_t Cmd) { ADS_NSS6(0); HAL_SPI_Transmit(&hspi2,&Cmd,1,HAL_MAX_DELAY); ADS_NSS6(1); } /******************************************************************************* * Function Name : SPI_ADS1247_WriteReg* Description : 写ADS1247的寄存器* Input : 发送寄存器地址 发送数据字节* Output : *******************************************************************************/ void ADS1247_WriteReg(uint8_t RegAddr,uint8_t *Buffer,uint8_t Length) { uint8_t Cmd[2]; ADS_NSS6(0); Cmd[0]=ADS1247_CMD_WREG|(RegAddr&0x0f); Cmd[1]=(Length-1)&0x0f; HAL_SPI_Transmit(&hspi2, Cmd, 2,HAL_MAX_DELAY); //指定向指定寄存器写入指定字节数据 HAL_SPI_Transmit(&hspi2, Buffer, Length,HAL_MAX_DELAY); //发送数据字节 ADS_NSS6(1);}/******************************************************************************* * Function Name : ADS1247_ReadReg * Description : 读寄存器* Input : 发送寄存器地址 发送数据字节* Output : *******************************************************************************/void ADS1247_ReadReg(uint8_t RegAddr,uint8_t *Buffer,uint8_t Length){ uint8_t Cmd[2]; ADS_NSS6(0); Cmd[0]=ADS1247_CMD_RREG|(RegAddr&0x0f); Cmd[1]=(Length-1)&0x0f; HAL_SPI_Transmit(&hspi2,Cmd, 2,HAL_MAX_DELAY); //发送命令 HAL_SPI_Receive(&hspi2, Buffer, Length, HAL_MAX_DELAY);//接收寄存器数据 ADS_NSS6(1);}/******************************************************************************* * Function Name : SPI_ADS1247_WaitBusy * Description : 判断忙状态* Input : * Output : *******************************************************************************/ void ADS1247_WaitBusy() { uint8_t i=0; while(ADS_RDY6) { i++; HAL_Delay(5); if(i>200) break; }} /******************************************************************************* * Function Name : ADS1247_Calibrate * Description : ADS1247校准* Input : None * Output : None * Return : None*******************************************************************************/ //static uint8_t ADS1247_Calibrate(uint8_t Gain) //{ // uint8_t R=0;// uint8_t Cmd; // ADS1247_WriteReg(ADS1247_REG_SYS0,&Gain,1); //设置增益和ADC输出速率 // Cmd=0x20; //0 01 00 000 启动内部参考电压,选择REF0作为参考电压输入; // ADS1247_WriteReg(ADS1247_REG_MUX1,&Cmd,1); // // ADS1247_WriteCmd(ADS1247_CMD_SELFOCAL); //自偏校准// R |= ADS1247_WaitBusy(); //等待完成 // Cmd=0x21; //0 01 00 001// ADS1247_WriteReg(ADS1247_REG_MUX1,&Cmd,1); //设置系统监测外部参考电压偏移测量 // // ADS1247_WriteCmd(ADS1247_CMD_SYSOCAL); //系统偏移校准// R |= ADS1247_WaitBusy(); //等待完成 // // Cmd=0x22; //设置系统监测外部参考电压偏移测量 // ADS1247_WriteReg(ADS1247_REG_MUX1,&Cmd,1); // // ADS1247_WriteCmd(ADS1247_CMD_SYSOCAL); //系统增益校准 // R |= ADS1247_WaitBusy(); //等待完成 // return R;//}/******************************************************************************* * Function Name : ADS1247_Init * Description : ADS1247初始化* Input : None * Output : None * Return : None*******************************************************************************/ void ADS1247_Init(){ uint8_t Cmd; ADS_NSS6(0); ADS1247_WriteCmd(ADS1247_CMD_RESET); HAL_Delay(20); Cmd=0x0A; //00 001 010 不开启传感器检测;选定输入通道组合P-AIN1,N-AIN2; ADS1247_WriteReg(ADS1247_REG_MUX0,&Cmd,1); Cmd=0x00; //0000 0110 不设置偏置电压 ADS1247_WriteReg(ADS1247_REG_VBIAS,&Cmd,1); Cmd=0x20; //0 01 10 000 启动内部参考电压,选择REFP0:REFN0两端电压作为ADC参考电平 ADS1247_WriteReg(ADS1247_REG_MUX1,&Cmd,1); Cmd=0x22; //0 010 0010 设置增益值、ADC输出数据率 4,20SPS ADS1247_WriteReg(ADS1247_REG_SYS0,&Cmd,1); // ADS1247_Calibrate(GainDataRate); Cmd=0x06; //xxxxx 110 设置IDAC1=IDAC2电流源为1mA ADS1247_WriteReg(ADS1247_REG_IDAC0,&Cmd,1); Cmd=0x03; //0000 0011 控制电流源输出引脚 IDAC1->AIN0 IDAC2->AIN3. ADS1247_WriteReg(ADS1247_REG_IDAC1,&Cmd,1); Cmd=0x00; //GPIO3-AIN3 GPIO2-AIN2 GPIO1-REFN0 GPIO0-REFP0 ADS1247_WriteReg(ADS1247_REG_GPIOCFG,&Cmd,1); Cmd=0x00; // ADS1247_WriteReg(ADS1247_REG_GPIODIR,&Cmd,1); Cmd=0x00; // ADS1247_WriteReg(ADS1247_REG_GPIODAT,&Cmd,1);// Delay_us(100); ADS_NSS6(1);}/******************************************************************************* * Function Name : ADS1247_ReadData_RTD * Description : 连续读ADS1247 转换值* Input : None * Output : None * Return : Register data*******************************************************************************/ uint32_t ADS1247_ReadData_RTD(void){ uint8_t Cmd[4]={ADS1247_CMD_RDATA,ADS1247_CMD_NOP,ADS1247_CMD_NOP,ADS1247_CMD_NOP}; uint8_t Buf[4]; uint32_t Data=0; ADS1247_WaitBusy(); ADS_NSS6(0); HAL_SPI_TransmitReceive(&hspi2,Cmd,Buf,4,1000); ADS_NSS6(1); Data=Buf[1]; Data=(Data<<8)|Buf[2]; Data=(Data<<8)|Buf[3]; return Data; }
0
|
2个回答
|
|
|