程序如下:
void ADS1247Wakeup(void) [ ADS1247PinCs(0); ADS1247TxRxByte(0x00); //reg ADS1247PinCs(1); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/
void ADS1247Sleep(void) [ ADS1247PinCs(0); ADS1247TxRxByte(0x02); //reg ADS1247PinCs(1); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/
void ADS1247Sync(void) [ ADS1247PinCs(0); ADS1247TxRxByte(0x04); ADS1247TxRxByte(0x04); ADS1247PinCs(1); ] /********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/
void ADS1247Reset(void) [ uint16 i; ADS1247PinCs(0); ADS1247TxRxByte(0x06); ADS1247PinCs(1); for (i=60000; i!=0; i--); ADS1247PinReset(0); for (i=60000; i!=0; i--); ADS1247PinReset(1); for (i=60000; i!=0; i--); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/
uint32 ADS1247RData(void) [ uint32 res = 0; ADS1247PinCs(0);
ADS1247TxRxByte(0x12); res = ADS1247TxRxByte(0); res <<= 8; res |= ADS1247TxRxByte(0); res <<= 8; res |= ADS1247TxRxByte(0); ADS1247PinCs(1); return res; ]
uint32 ADS1247ReadADC(void) [ uint32 res = 0; ADS1247PinCs(0); res = ADS1247TxRxByte(0); res <<= 8; res |= ADS1247TxRxByte(0); res <<= 8; res |= ADS1247TxRxByte(0); ADS1247PinCs(1); return res; ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/
void ADS1247RDataC(void) [ ADS1247PinCs(0); ADS1247TxRxByte(0x14); ADS1247PinCs(1); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/
void ADS1247SDataC(void) [ ADS1247PinCs(0); ADS1247TxRxByte(0x17); ADS1247PinCs(1); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/
void ADS1247SysOCal(void) [ ADS1247PinCs(0); ADS1247TxRxByte(0x60); ADS1247PinCs(1); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************
/ void ADS1247SysGCal(void) [ ADS1247PinCs(0); ADS1247TxRxByte(0x61); ADS1247PinCs(1); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/ void ADS1247SelfOCal(void) [ ADS1247PinCs(0); ADS1247TxRxByte(0x62); ADS1247PinCs(1); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/ void ADS1247ReadReg(uint8 reg, uint8 *pcmd, uint8 len) [ ADS1247PinCs(0); ADS1247TxRxByte(reg | 0x20); //reg ADS1247TxRxByte(len - 1); //len while (len != 0) [ *pcmd = ADS1247TxRxByte(0x00); pcmd++; len--; ] ADS1247PinCs(1); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/ void ADS1247WriteReg(uint8 reg, uint8 *pcmd, uint8 len) [ ADS1247PinCs(0); ADS1247TxRxByte(reg | 0x40); //reg ADS1247TxRxByte(len - 1); //len while (len != 0) [ ADS1247TxRxByte(*pcmd); pcmd++; len--; ] ADS1247PinCs(1); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/ static uint8 ADS1247TxRxByte(uint8 dt) [ uint8 res = 0; uint8 i; for (i=8; i!=0; i--) [ ADS1247PinSdi(((dt & 0x80) != 0) ? 1 : 0); ADS1247PinSclk(1); res <<= 1; if (ADS1247PinSdo() != 0) res |= 0x01; ADS1247PinSclk(0); dt <<= 1; ] return res; ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/ static void AD1247IOInit(void) [ GPIO_InitTypeDef GPIO_InitStructure; /* GPIO 定义 */ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //=========== // GPIOA GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | // ADS1247 SCLK GPIO_Pin_7; // ADS1247 SDI GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); // IN GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; // ADS1247 SDO GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOA, &GPIO_InitStructure); //=========== // GPIOB GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | // ADS1247 RESET GPIO_Pin_0; // ADS1247 START GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOB, &GPIO_InitStructure);
//=========== // GPIOC GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; // ADS1247 CS GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOC, &GPIO_InitStructure); //IN GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; // ADS1247 DRDY GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOC, &GPIO_InitStructure); ADS1247PinReset(1); ADS1247PinCs(1); ADS1247PinStart(1); ADS1247PinSclk(0); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/ static void ADS1247PinSclk(uint8 st) [ GPIO_WriteBit(GPIOA, GPIO_Pin_5, (st == 0) ? Bit_RESET : Bit_SET); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/ static void ADS1247PinSdi(uint8 st) [ GPIO_WriteBit(GPIOA, GPIO_Pin_7, (st == 0) ? Bit_RESET : Bit_SET); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/ static uint8 ADS1247PinSdo(void) [ uint8 res; res = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_6); return res; ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/ static void ADS1247PinReset(uint8 st) [ GPIO_WriteBit(GPIOB, GPIO_Pin_1, (st == 0) ? Bit_RESET : Bit_SET); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/ void ADS1247PinStart(uint8 st) [ GPIO_WriteBit(GPIOB, GPIO_Pin_0, (st == 0) ? Bit_RESET : Bit_SET); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/ static void ADS1247PinCs(uint8 st) [ GPIO_WriteBit(GPIOC, GPIO_Pin_5, (st == 0) ? Bit_RESET : Bit_SET); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/ uint8 ADS1247PinDRdy(void) [ uint8 res; res = GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_4); return res; ]
程序中调用的是ADS1247ReadADC() 函数读取数据,调用ADS1247RData(void)函数与调用ADS1247RData()函数现象一样
PGA设置为32,与设置成1没有什么明显的改善。原理图上的RDT RDW Rb没有焊接,AIN2,AIN3没有使用
程序如下:
void ADS1247Wakeup(void) [ ADS1247PinCs(0); ADS1247TxRxByte(0x00); //reg ADS1247PinCs(1); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/
void ADS1247Sleep(void) [ ADS1247PinCs(0); ADS1247TxRxByte(0x02); //reg ADS1247PinCs(1); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/
void ADS1247Sync(void) [ ADS1247PinCs(0); ADS1247TxRxByte(0x04); ADS1247TxRxByte(0x04); ADS1247PinCs(1); ] /********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/
void ADS1247Reset(void) [ uint16 i; ADS1247PinCs(0); ADS1247TxRxByte(0x06); ADS1247PinCs(1); for (i=60000; i!=0; i--); ADS1247PinReset(0); for (i=60000; i!=0; i--); ADS1247PinReset(1); for (i=60000; i!=0; i--); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/
uint32 ADS1247RData(void) [ uint32 res = 0; ADS1247PinCs(0);
ADS1247TxRxByte(0x12); res = ADS1247TxRxByte(0); res <<= 8; res |= ADS1247TxRxByte(0); res <<= 8; res |= ADS1247TxRxByte(0); ADS1247PinCs(1); return res; ]
uint32 ADS1247ReadADC(void) [ uint32 res = 0; ADS1247PinCs(0); res = ADS1247TxRxByte(0); res <<= 8; res |= ADS1247TxRxByte(0); res <<= 8; res |= ADS1247TxRxByte(0); ADS1247PinCs(1); return res; ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/
void ADS1247RDataC(void) [ ADS1247PinCs(0); ADS1247TxRxByte(0x14); ADS1247PinCs(1); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/
void ADS1247SDataC(void) [ ADS1247PinCs(0); ADS1247TxRxByte(0x17); ADS1247PinCs(1); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/
void ADS1247SysOCal(void) [ ADS1247PinCs(0); ADS1247TxRxByte(0x60); ADS1247PinCs(1); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************
/ void ADS1247SysGCal(void) [ ADS1247PinCs(0); ADS1247TxRxByte(0x61); ADS1247PinCs(1); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/ void ADS1247SelfOCal(void) [ ADS1247PinCs(0); ADS1247TxRxByte(0x62); ADS1247PinCs(1); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/ void ADS1247ReadReg(uint8 reg, uint8 *pcmd, uint8 len) [ ADS1247PinCs(0); ADS1247TxRxByte(reg | 0x20); //reg ADS1247TxRxByte(len - 1); //len while (len != 0) [ *pcmd = ADS1247TxRxByte(0x00); pcmd++; len--; ] ADS1247PinCs(1); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/ void ADS1247WriteReg(uint8 reg, uint8 *pcmd, uint8 len) [ ADS1247PinCs(0); ADS1247TxRxByte(reg | 0x40); //reg ADS1247TxRxByte(len - 1); //len while (len != 0) [ ADS1247TxRxByte(*pcmd); pcmd++; len--; ] ADS1247PinCs(1); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/ static uint8 ADS1247TxRxByte(uint8 dt) [ uint8 res = 0; uint8 i; for (i=8; i!=0; i--) [ ADS1247PinSdi(((dt & 0x80) != 0) ? 1 : 0); ADS1247PinSclk(1); res <<= 1; if (ADS1247PinSdo() != 0) res |= 0x01; ADS1247PinSclk(0); dt <<= 1; ] return res; ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/ static void AD1247IOInit(void) [ GPIO_InitTypeDef GPIO_InitStructure; /* GPIO 定义 */ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //=========== // GPIOA GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | // ADS1247 SCLK GPIO_Pin_7; // ADS1247 SDI GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); // IN GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; // ADS1247 SDO GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOA, &GPIO_InitStructure); //=========== // GPIOB GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | // ADS1247 RESET GPIO_Pin_0; // ADS1247 START GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOB, &GPIO_InitStructure);
//=========== // GPIOC GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; // ADS1247 CS GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOC, &GPIO_InitStructure); //IN GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; // ADS1247 DRDY GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOC, &GPIO_InitStructure); ADS1247PinReset(1); ADS1247PinCs(1); ADS1247PinStart(1); ADS1247PinSclk(0); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/ static void ADS1247PinSclk(uint8 st) [ GPIO_WriteBit(GPIOA, GPIO_Pin_5, (st == 0) ? Bit_RESET : Bit_SET); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/ static void ADS1247PinSdi(uint8 st) [ GPIO_WriteBit(GPIOA, GPIO_Pin_7, (st == 0) ? Bit_RESET : Bit_SET); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/ static uint8 ADS1247PinSdo(void) [ uint8 res; res = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_6); return res; ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/ static void ADS1247PinReset(uint8 st) [ GPIO_WriteBit(GPIOB, GPIO_Pin_1, (st == 0) ? Bit_RESET : Bit_SET); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/ void ADS1247PinStart(uint8 st) [ GPIO_WriteBit(GPIOB, GPIO_Pin_0, (st == 0) ? Bit_RESET : Bit_SET); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/ static void ADS1247PinCs(uint8 st) [ GPIO_WriteBit(GPIOC, GPIO_Pin_5, (st == 0) ? Bit_RESET : Bit_SET); ]
/********************************************************************************** ** 函数名称: ** 功 能: ** 输入参数: ** 输出参数: ** 返 回: ***********************************************************************************/ uint8 ADS1247PinDRdy(void) [ uint8 res; res = GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_4); return res; ]
程序中调用的是ADS1247ReadADC() 函数读取数据,调用ADS1247RData(void)函数与调用ADS1247RData()函数现象一样
PGA设置为32,与设置成1没有什么明显的改善。原理图上的RDT RDW Rb没有焊接,AIN2,AIN3没有使用
举报