;______________________________________ ; SNIFFER I2C ; Matériel : ATtiny 45/85 4MHz 5V ; LCD1602 I²C ; (c) sammy76.free.fr ; V1.0 2016/06/01 Juin 2016 ;______________________________________ ; V1.0 SNIFFER I2C ; (c) Sammy76.free.fr ; Maj : 13/11/2016 ;______________________________________ ; ATtiny45 - 8MHz interne ; +-\/-+ ; PB5 1|- -|8 Vcc ;Trigger PB3 2|- -|7 PB2 SENSELED ; Echo PB4 3|- -|6 PB1 SDA ; GND 4|- -|5 PB0 SCL ; +----+ ;Registres utilisés r16 (A),r19 (Adresse I²C=ADR), r20 (DATA) ; Code : 366 words (732 bytes) ; Data : 162 bytes ; EEPROM : 0 bytes .CSEG .include "../includes/tn85def.inc" .define F_CPU 16500000 ;16.5MHz .def A = r16 ; ;.def ADR = r19 ; .equ SENSELED=PB1 ; SENSELED pin (Output on AVR) ;.equ ERRORLED=PB4 ; ERRORLED pin (Output on AVR) ; I2C Device addressing ;.equ LCD1602 = 0x3F ; LCD1602 address byte ;----------------------------------------------------------------- .org 0000 ;************************************************ ;* Interrupt Vectors * ;************************************************ zRESET: ; Reset Handler rjmp ON_RESET zINT0addr: ; External Interrupt 0 reti zPCI0addr: ; Pin change Interrupt Request 0 reti zOC1Aaddr: ; Timer/Counter1 Compare Match 1A reti zOVF1addr: ; Timer/Counter1 Overflow reti zOVF0addr: ; Timer/Counter0 Overflow reti zERDYaddr: ; EEPROM Ready reti zACIaddr: ; Analog comparator reti zADCCaddr: ; ADC Conversion ready reti zOC1Baddr: ; Timer/Counter1 Compare Match B reti zOC0Aaddr: ; Timer/Counter0 Compare Match A reti zOC0Baddr: ; Timer/Counter0 Compare Match B reti zWDTaddr: ; Watchdog Time-out reti ;rjmp WDTinterrupt zUSI_STARTaddr: ; USI START reti zUSI_OVFaddr: ; USI Overflow reti ;***** Include modules .include "../utils/i2c_attiny.inc" .include "../utils/lcd_.inc" .include "../utils/wait.inc" ;______________________________________ ; SETUP ;______________________________________ ON_RESET: ldi A, LOW(RAMEND) ;Setup of stack pointer 0x15F out SPL, A ldi A, HIGH(RAMEND) out SPH, A ldi A,0b10000000 ;Attention, ces 2 instructions sont importantes pour le changement de fréquence (sécurité AVR) out CLKPR,A ldi A,0b0000000 ;divise par 0le clock RC de 8MHz, donc 8MHz out CLKPR,A ;Eteint le CAN cbi ADCSRA, ADEN ;switch Analog to Digitalconverter OFF ;______________________________________ ; BOUCLE PRINCIPALE ;______________________________________ rcall LCD_Init ldi DATA,0x40 ;chr 0 rcall LCD_DATA_write_cmd ldi ZL, LOW(copyright<<1) ldi ZH, HIGH(copyright<<1) rcall LCD_write_string rcall I2CStop ldi A,5 rcall WaitMiliseconds ;5ms ldi YL,Low(adresse<<1) ldi YH,high(adresse<<1) clr ADR MAIN_LOOP: test_i2c: rcall I2CStart mov DATA,ADR ;Write Mode add DATA,DATA rcall I2CSendAddress brne suite ; No ack! st Y+,ADR suite: rcall I2CStop ldi A,5 rcall WaitMiliseconds ;5ms inc ADR cpi ADR,0x7F brne test_i2c ;______________________________________ ; Fin récupération des adresses ;______________________________________ ldi ADR,0xff st Y+,ADR ldi YL,Low(adresse<<1) ldi YH,HIGH(adresse<<1) rcall LCD_Init rcall LCD_clear ldi ZL, LOW(txt1<<1) ldi ZH, HIGH(txt1<<1) rcall LCD_write_string Lit_i2C: ldi ZL, LOW(L1<<1) ldi ZH, HIGH(L1<<1) ld DATA, Y+ ;DATA=(Y) Y=Y+1 ser A ;0xFF cp DATA,A ;Si egal fin breq fin_lit_i2C ldi A,'0' st Z+,A ldi A,'x' st Z+,A rcall conv_ASC ldi A,' ' st Z+,A ;ser A ;st Z+,A rcall findI2C ;DATA=ADRI2C ;st Z+,A ;Met l'adresse ldi DATA,0xC0 ;Ligne 2 1100 0000 0x40 rcall LCD_DATA_write_cmd ldi ZL, LOW(L1<<1) ldi ZH, HIGH(L1<<1) rcall LCD_write_string_sram ;"Adresse I2C :" ldi A, 1 rcall Waitseconds ;1s rjmp Lit_i2C fin_lit_i2C: rjmp MAIN_LOOP conv_ASC: mov A,DATA swap A ;HIGH rcall conv_digit mov A,DATA ;LOW rcall conv_digit ret conv_digit: andi A,0x0F cpi A,0x0A BRLT suit_asc1 ;A<10 subi A,0x09 ori A,0x40 rjmp suit_asc2 suit_asc1: ori A,0x30 suit_asc2: st Z+,A ret findI2C: ;DATA=Adresse de l'I2C connue ou pas mov XL,ZL ;X point Dseg L1 mov XH,ZH ldi ZL, LOW(tabl_i2c<<1) ldi ZH, HIGH(tabl_i2c<<1) findI2C_a: lpm A,Z+ cpi A,0xFF breq findI2C_b ;Inconnue cp A,DATA breq findI2C_b adiw ZL,2 rjmp findI2C_a ;ZH:ZL point l'adresse du texte findI2C_b: lpm r0,Z+ lpm r1,Z+ mov ZL,r0 mov ZH,r1 findI2C_c: lpm A,Z+ cpi A,0xFF breq endfindI2C st X+,A rjmp findI2C_c endfindI2C: ser A st X+,A ;Met l'adresse ret ;------------------------------------------------------------------ copyright: .db 0b01110, 0b10101, 0b11011, 0b11001, 0b11001, 0b11011, 0b10101, 0b01110,0xFF,0 txt1: .db "ADR: scanner I2C",0xFF,0 tabl_i2c: .db 0x27,low(txt_LCDI2C<<1),high(txt_LCDI2C<<1),0x3C,low(txt_HMC5883L_W<<1),high(txt_HMC5883L_W<<1) .db 0x3C,low(txt_HMC5883L_R<<1),high(txt_HMC5883L_R<<1),0x3F,low(txt_LCDI2C<<1),high(txt_LCDI2C<<1) .db 0x48,low(txt_ADS1115<<1),high(txt_ADS1115<<1),0x68,low(txt_DS3231<<1),high(txt_DS3231<<1) .db 0x77,low(txt_BMP180<<1),high(txt_BMP180<<1),0xFF,low(txt_Inconnue<<1),high(txt_Inconnue<<1) ;MCP23008 i2c 8 input/output port expander 0x20 0x21 0x22 0x23 0x24 0x25 0x26 0x27 ;MCP23017 i2c 16 input/output port expander 0x20 0x21 0x22 0x23 0x24 0x25 0x26 0x27 ;HMC5883L 8-bit slave address is 0x3C for write operations, or 0x3D for read operations txt_HMC5883L_W: .db "HMC5883L WT",0xFF txt_HMC5883L_R: .db "HMC5883L RD",0xFF txt_ADS1115: .db "ADS1115 ",0xFF txt_DS3231: .db "DS3231 ",0xFF txt_LCDI2C: .db "LCD I2C ",0xFF txt_BMP180: .db "BMP085/180 ",0xFF txt_Inconnue: .db "Inconnue ",0xFF .dseg .org 0x60 L1: .byte 17 L2: .byte 17 adresse: .byte 128; //