;______________________________________ ; ADS1115/CAN 12 bits/4 entrées ; ; Matériel : ATtiny 45/85 8MHz 5V ; ADS1115 I²C ; (c) sammy76.free.fr ; V1.0 2016/06/01 Juin 2016 ;______________________________________ ; V1.0 ESSAI ; ATtiny45 - 8MHz interne ; +-\/-+ ; PB5 1|- -|8 Vcc ; PB3 2|- -|7 PB2 SENSELED ; PB4 3|- -|6 PB1 SDA LCD/ADS1115 ; GND 4|- -|5 PB0 SCL LCD/ADS1115 ; +----+ ;I2C : Registres utilisés r16 (A),r19 (Adresse I²C), r20 (DATA) ; ;.CSEG ;.include "../includes/tn45def.inc" ;.include "../utils/i2c_attiny.inc" ;.def A = r16 ; ;.def rBin1L = r5 ; ;.def rBin1H = r6 ; ; I2C Device addressing .equ ADS1115 = 0x48 ; ADS1115 address byte ;ADS1115 .equ ADS1015_REG_POINTER_CONFIG=(0x01) .equ ADS1015_REG_POINTER_CONVERT=(0x00) .equ CFG_PGA_6_144V = (0x0000) ; +/-6.144V range = Gain 2/3 .equ CFG_PGA_4_096V = (0x0200) ; +/-4.096V range = Gain 1 .equ CFG_PGA_2_048V = (0x0400) ; +/-2.048V range = Gain 2 (default) .equ CFG_PGA_1_024V = (0x0600) ; +/-1.024V range = Gain 4 .equ CFG_PGA_0_512V = (0x0800) ; +/-0.512V range = Gain 8 .equ CFG_PGA_0_256V = (0x0A00) ; +/-0.256V range = Gain 16.144V range = Gain 2/3 .equ CFG_MUX_DIFF_0_1 =(0x0000) ; Differential P = AIN0, N = AIN1 (default) .equ CFG_MUX_DIFF_0_3 =(0x1000) ; Differential P = AIN0, N = AIN3 .equ CFG_MUX_DIFF_1_3 =(0x2000) ; Differential P = AIN1, N = AIN3 .equ CFG_MUX_DIFF_2_3 =(0x3000) ; Differential P = AIN2, N = AIN3 .equ CFG_MUX_SINGLE_0 =(0x4000) ; Single-ended AIN0 .equ CFG_MUX_SINGLE_1 =(0x5000) ; Single-ended AIN1 .equ CFG_MUX_SINGLE_2 =(0x6000) ; Single-ended AIN2 .equ CFG_MUX_SINGLE_3 =(0x7000) ; Single-ended AIN3 .equ CFG_DR_128SPS =(0x0000) ; 128 samples per second .equ CFG_DR_250SPS =(0x0020) ; 250 samples per second .equ CFG_DR_490SPS =(0x0040) ; 490 samples per second .equ CFG_DR_920SPS =(0x0060) ; 920 samples per second .equ CFG_DR_1600SPS =(0x0080) ; 1600 samples per second (default) .equ CFG_DR_2400SPS =(0x00A0) ; 2400 samples per second .equ CFG_DR_3300SPS =(0x00C0) ; 3300 samples per second .equ CFG_CQUE_NONE =(0x0003) ; Disable the comparator and put ALERT/RDY in high state (default) .equ CFG_CLAT_NONLAT =(0x0000) ; Non-latching comparator (default) .equ CFG_CPOL_ACTVLOW =(0x0000) ; ALERT/RDY pin is low when active (default) .equ CFG_CMODE_TRAD =(0x0000) ; Traditional comparator with hysteresis (default) .equ CFG_MODE_SINGLE =(0x0100) ; Power-down single-shot mode (default) .equ CFG_CONFIG_OS_SINGLE = (0x8000) ; Write: Set to start a single-conversion .equ config_ads = CFG_MUX_SINGLE_0 | CFG_PGA_4_096V | CFG_CQUE_NONE | CFG_CLAT_NONLAT | CFG_CPOL_ACTVLOW | CFG_CMODE_TRAD | CFG_DR_1600SPS | CFG_MODE_SINGLE | CFG_CONFIG_OS_SINGLE ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;ADS1015 READ 0x00 ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ADS1015_read: rcall I2CStart ldi DATA,ADS1115*2 ;Write rcall I2CSendByte ldi DATA,ADS1015_REG_POINTER_CONFIG rcall I2CSendByte ldi DATA,(config_ads >> 8) rcall I2CSendByte ldi DATA,(config_ads & 0xFF) rcall I2CSendByte rcall I2CStop ldi A,8 ;Wait for the conversion to complete rcall WaitMiliseconds rcall I2CStart ldi DATA,ADS1115*2 ;Write rcall I2CSendByte ldi DATA,ADS1015_REG_POINTER_CONVERT rcall I2CSendByte rcall I2CStop rcall I2CStart ldi A,8 ;Wait for the conversion to complete rcall WaitMiliseconds ldi DATA,ADS1115*2 | 1 ;Read rcall I2CSendByte rcall I2CReadByte mov rBin1H,A ;AJ Octet Haut rcall I2CReadByte mov rBin1L,A rcall I2CStop ret