ADS读出的值用LCD显示:
第一通道和第四通道0电压显示不正常,655xx,接近AD的最大值。加了电压,反而AD值减小
第二通道和第三通道正常!
#define ADS1115_DEVICE_ADDR 0x90
#defineADA1115_CONVERSION_REG_ADDR 0x00
#define ADA1115_CONFIG_REG_ADDR 0x01
#defineADA1115_Lo_THRESH_REG_ADDR 0x02
#defineADA1115_Ho_THRESH_REG_ADDR 0x03
unsigned int ADS1115_Read(unsigned ad_ch)
{
unsigned int ad_tmp = 0;
I2C_Start();
I2C_SendDAdr(ADS1115_DEVICE_ADDR);
I2C_Ack();
I2C_SendDat(ADA1115_CONFIG_REG_ADDR);//写配置寄存器
I2C_Ack();
I2C_SendDat(0xc2|((ad_ch&0b00000011)<<4));
I2C_Ack();
//I2C_SendDat(0xe2);
I2C_SendDat(0x82);
I2C_Ack();
I2C_stop();
Delay_us(1000);
I2C_Start();
I2C_SendDAdr(ADS1115_DEVICE_ADDR);
I2C_Ack();
I2C_SendDat(ADA1115_CONVERSION_REG_ADDR);
I2C_stop();
Delay_us(1000);
I2C_Start();
I2C_SendDAdr(ADS1115_DEVICE_ADDR+1);
I2C_Ack();
ad_tmp |= (unsigned int)I2C_RcvDat()<<8;
I2C_Ack();
ad_tmp |= (unsigned int)I2C_RcvDat();
I2C_NAck()
I2C_stop();
return ad_tmp;
}
int main(void)
{
int i;
CLK_Init();
LCD_IO_Init();
LCD_Init();
I2C_Init();
Delay_us(50000);
Delay_us(50000);
while (1)
{
LCD_Print(1, 0, "0-");
LCD_Print(0, 0, Int2Str(ADS1115_Read(0)));
Delay_us(5000);
LCD_Print(1, 8, "1-");
LCD_Print(0, 0, Int2Str(ADS1115_Read(1)));
Delay_us(5000);
LCD_Print(2, 0, "2-");
LCD_Print(0, 0, Int2Str(ADS1115_Read(2)));
Delay_us(5000);
LCD_Print(2, 8, "3-");
LCD_Print(0, 0, Int2Str(ADS1115_Read(3)));
Delay_us(5000);
}
return 0;
}转载
|