TI 公司的ADS1256芯片,是一款24BIT delta-sigma ADC.转换速度为30kSPS.
上图为ADS1256芯片结构和引脚图,从图可以看出ADS1256的通道资源比较丰富,可以配置成8个单端ADC通道,也可以配置成4个差分通道。ADS1256的通信接口为串行接口,同时还有4个通用的IO口,不过这四个IO口不经常用到。
ADS1256内部有许多寄存器需要配置,相较于ADS1232用起来要复杂的多。
下面介绍一下ADS1256的初始化。
void bsp_InitADS1256(void)
{
//SYNC_1();
GPIO_SetBits(GPIOD,GPIO_Pin_1);
//RST_1();
GPIO_SetBits(GPIOB,GPIO_Pin_10);
//CS_1();
GPIO_SetBits(GPIOE,GPIO_Pin_9);
//SCK_0(); /* SPI总线空闲时,钟线是低电平 */
GPIO_ResetBits(GPIOE,GPIO_Pin_15);
//DI_1();
GPIO_SetBits(GPIOC,GPIO_Pin_9);
ADS1256_CfgADC(ADS1256_GAIN_1, ADS1256_30000SPS); /* 配置ADC参数: 增益1:1, 数据输出速率 1KHz */
}
ADS1256_CfgADC(ADS1256_GAIN_1, ADS1256_30000SPS)的代码如下:
void ADS1256_CfgADC(ADS1256_GAIN_E _gain, ADS1256_DRATE_E _drate)
{
g_tADS1256.Gain = _gain;
g_tADS1256.DataRate = _drate;
//ADS1256_StopScan(); /* 暂停CPU中断 */
//ADS1256_ResetHard(); /* 硬件复位 */
ADS1256_WaitDRDY();
{
uint8_t buf[4]; /* 暂存ADS1256 寄存器配置参数,之后连续写4个寄存器 */
/* 状态寄存器定义
Bits 7-4 ID3, ID2, ID1, ID0 Factory Programmed Identification Bits (Read Only)
Bit 3 ORDER: Data Output Bit Order
0 = Most Significant Bit First (default)
1 = Least Significant Bit First
Input data is always shifted in most significant byte and bit first. Output data is always shifted out most significant
byte first. The ORDER bit only controls the bit order of the output data within the byte.
Bit 2 ACAL : Auto-Calibration
0 = Auto-Calibration Disabled (default)
1 = Auto-Calibration Enabled
When Auto-Calibration is enabled, self-calibration begins at the completion of the WREG command that changes
the PGA (bits 0-2 of ADCON register), DR (bits 7-0 in the DRATE register) or BUFEN (bit 1 in the STATUS register)
values.
Bit 1 BUFEN: Analog Input Buffer Enable
0 = Buffer Disabled (default)
1 = Buffer Enabled
Bit 0 DRDY : Data Ready (Read Only)
This bit duplicates the state of the DRDY pin.
ACAL=1使能自校准功能。当 PGA,BUFEEN, DRATE改变时会启动自校准
*/
buf[0] = (0 << 3) | (0 << 2) | (0 << 1);//此处(0 << 1)表示关闭BUFFER,改为(1 << 1)表示打开BUFFER
/*
打开或关闭BUFFER会影响芯片可采集电压范围.详见ADS1256数据手册第3页
关闭BUFFER,采集范围:AGND-0.1 ~ AVDD+0.1
打开BUFFER,采集范围:AGND ~ AVDD+2.0
*/
buf[1] = 0x23; /* 高四位0表示AINP接 AIN0, 低四位8表示 AINN 固定接 AINCOM */
/* ADCON: A/D Control Register (Address 02h)
Bit 7 Reserved, always 0 (Read Only)
Bits 6-5 CLK1, CLK0 : D0/CLKOUT Clock Out Rate Setting
00 = Clock Out OFF
01 = Clock Out Frequency = fCLKIN (default)
10 = Clock Out Frequency = fCLKIN/2
11 = Clock Out Frequency = fCLKIN/4
When not using CLKOUT, it is recommended that it be turned off. These bits can only be reset using the RESET pin.
Bits 4-2 SDCS1, SCDS0: Sensor Detect Current Sources
00 = Sensor Detect OFF (default)
01 = Sensor Detect Current = 0.5 μ A
10 = Sensor Detect Current = 2 μ A
11 = Sensor Detect Current = 10μ A
The Sensor Detect Current Sources can be activated to verify the integrity of an external sensor supplying a signal to the
ADS1255/6. A shorted sensor produces a very small signal while an open-circuit sensor produces a very large signal.
Bits 2-0 PGA2, PGA1, PGA0: Programmable Gain Amplifier Setting
000 = 1 (default)
001 = 2
010 = 4
011 = 8
100 = 16
101 = 32
110 = 64
111 = 64
*/
buf[2] = (0 << 5) | (0 << 3) | (_gain << 0);
//ADS1256_WriteReg(REG_ADCON, (0 << 5) | (0 << 2) | (GAIN_1 << 0)); /* 选择1;1增益, 输入正负5V */
/* 因为切换通道和读数据耗时 123uS, 因此扫描中断模式工作时,最大速率 = DRATE_1000SPS */
buf[3] = s_tabDataRate[_drate]; // DRATE_10SPS; /* 选择数据输出速率 */
//CS_0(); /* SPI片选 = 0 */
GPIO_ResetBits(GPIOE,GPIO_Pin_9);
ADS1256_Send8Bit(CMD_WREG | 0); /* 写寄存器的命令, 并发送寄存器地址 */
ADS1256_Send8Bit(0x03); /* 寄存器个数 - 1, 此处3表示写4个寄存器 */
ADS1256_Send8Bit(buf[0]); /* 设置状态寄存器 */
ADS1256_Send8Bit(buf[1]); /* 设置输入通道参数 */
ADS1256_Send8Bit(buf[2]); /* 设置ADCON控制寄存器,增益 */
ADS1256_Send8Bit(buf[3]); /* 设置输出数据速率 */
//CS_1(); /* SPI片选 = 1 */
GPIO_SetBits(GPIOE,GPIO_Pin_9);
//ADS1256_Self_Cal();
}
Delay_us(50);
}
版权声明:本文为CSDN博主「牛70611」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_42279760/article/details/120996970
TI 公司的ADS1256芯片,是一款24BIT delta-sigma ADC.转换速度为30kSPS.
上图为ADS1256芯片结构和引脚图,从图可以看出ADS1256的通道资源比较丰富,可以配置成8个单端ADC通道,也可以配置成4个差分通道。ADS1256的通信接口为串行接口,同时还有4个通用的IO口,不过这四个IO口不经常用到。
ADS1256内部有许多寄存器需要配置,相较于ADS1232用起来要复杂的多。
下面介绍一下ADS1256的初始化。
void bsp_InitADS1256(void)
{
//SYNC_1();
GPIO_SetBits(GPIOD,GPIO_Pin_1);
//RST_1();
GPIO_SetBits(GPIOB,GPIO_Pin_10);
//CS_1();
GPIO_SetBits(GPIOE,GPIO_Pin_9);
//SCK_0(); /* SPI总线空闲时,钟线是低电平 */
GPIO_ResetBits(GPIOE,GPIO_Pin_15);
//DI_1();
GPIO_SetBits(GPIOC,GPIO_Pin_9);
ADS1256_CfgADC(ADS1256_GAIN_1, ADS1256_30000SPS); /* 配置ADC参数: 增益1:1, 数据输出速率 1KHz */
}
ADS1256_CfgADC(ADS1256_GAIN_1, ADS1256_30000SPS)的代码如下:
void ADS1256_CfgADC(ADS1256_GAIN_E _gain, ADS1256_DRATE_E _drate)
{
g_tADS1256.Gain = _gain;
g_tADS1256.DataRate = _drate;
//ADS1256_StopScan(); /* 暂停CPU中断 */
//ADS1256_ResetHard(); /* 硬件复位 */
ADS1256_WaitDRDY();
{
uint8_t buf[4]; /* 暂存ADS1256 寄存器配置参数,之后连续写4个寄存器 */
/* 状态寄存器定义
Bits 7-4 ID3, ID2, ID1, ID0 Factory Programmed Identification Bits (Read Only)
Bit 3 ORDER: Data Output Bit Order
0 = Most Significant Bit First (default)
1 = Least Significant Bit First
Input data is always shifted in most significant byte and bit first. Output data is always shifted out most significant
byte first. The ORDER bit only controls the bit order of the output data within the byte.
Bit 2 ACAL : Auto-Calibration
0 = Auto-Calibration Disabled (default)
1 = Auto-Calibration Enabled
When Auto-Calibration is enabled, self-calibration begins at the completion of the WREG command that changes
the PGA (bits 0-2 of ADCON register), DR (bits 7-0 in the DRATE register) or BUFEN (bit 1 in the STATUS register)
values.
Bit 1 BUFEN: Analog Input Buffer Enable
0 = Buffer Disabled (default)
1 = Buffer Enabled
Bit 0 DRDY : Data Ready (Read Only)
This bit duplicates the state of the DRDY pin.
ACAL=1使能自校准功能。当 PGA,BUFEEN, DRATE改变时会启动自校准
*/
buf[0] = (0 << 3) | (0 << 2) | (0 << 1);//此处(0 << 1)表示关闭BUFFER,改为(1 << 1)表示打开BUFFER
/*
打开或关闭BUFFER会影响芯片可采集电压范围.详见ADS1256数据手册第3页
关闭BUFFER,采集范围:AGND-0.1 ~ AVDD+0.1
打开BUFFER,采集范围:AGND ~ AVDD+2.0
*/
buf[1] = 0x23; /* 高四位0表示AINP接 AIN0, 低四位8表示 AINN 固定接 AINCOM */
/* ADCON: A/D Control Register (Address 02h)
Bit 7 Reserved, always 0 (Read Only)
Bits 6-5 CLK1, CLK0 : D0/CLKOUT Clock Out Rate Setting
00 = Clock Out OFF
01 = Clock Out Frequency = fCLKIN (default)
10 = Clock Out Frequency = fCLKIN/2
11 = Clock Out Frequency = fCLKIN/4
When not using CLKOUT, it is recommended that it be turned off. These bits can only be reset using the RESET pin.
Bits 4-2 SDCS1, SCDS0: Sensor Detect Current Sources
00 = Sensor Detect OFF (default)
01 = Sensor Detect Current = 0.5 μ A
10 = Sensor Detect Current = 2 μ A
11 = Sensor Detect Current = 10μ A
The Sensor Detect Current Sources can be activated to verify the integrity of an external sensor supplying a signal to the
ADS1255/6. A shorted sensor produces a very small signal while an open-circuit sensor produces a very large signal.
Bits 2-0 PGA2, PGA1, PGA0: Programmable Gain Amplifier Setting
000 = 1 (default)
001 = 2
010 = 4
011 = 8
100 = 16
101 = 32
110 = 64
111 = 64
*/
buf[2] = (0 << 5) | (0 << 3) | (_gain << 0);
//ADS1256_WriteReg(REG_ADCON, (0 << 5) | (0 << 2) | (GAIN_1 << 0)); /* 选择1;1增益, 输入正负5V */
/* 因为切换通道和读数据耗时 123uS, 因此扫描中断模式工作时,最大速率 = DRATE_1000SPS */
buf[3] = s_tabDataRate[_drate]; // DRATE_10SPS; /* 选择数据输出速率 */
//CS_0(); /* SPI片选 = 0 */
GPIO_ResetBits(GPIOE,GPIO_Pin_9);
ADS1256_Send8Bit(CMD_WREG | 0); /* 写寄存器的命令, 并发送寄存器地址 */
ADS1256_Send8Bit(0x03); /* 寄存器个数 - 1, 此处3表示写4个寄存器 */
ADS1256_Send8Bit(buf[0]); /* 设置状态寄存器 */
ADS1256_Send8Bit(buf[1]); /* 设置输入通道参数 */
ADS1256_Send8Bit(buf[2]); /* 设置ADCON控制寄存器,增益 */
ADS1256_Send8Bit(buf[3]); /* 设置输出数据速率 */
//CS_1(); /* SPI片选 = 1 */
GPIO_SetBits(GPIOE,GPIO_Pin_9);
//ADS1256_Self_Cal();
}
Delay_us(50);
}
版权声明:本文为CSDN博主「牛70611」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_42279760/article/details/120996970
暂无评论