potøeboval bych poradit ohlednì komunikace s externí EEPROM pomocí I2C - myslím si, že kód mám správnì napsaný, pøesto z nìjakého dùvodu nedochází ke správnému zápisu (resp. žádnému) a se ètením to je podobné
![Sad :(](./images/smilies/icon_sad.gif)
Kód: Vybrat vše
; Pøeète 1 byt a uloží ho do promìnné EBYTE
@i2c_in_byte
CALL @i2c_high_sda
MOVLW 8
MOVWF rot
i2c_in_byte_rot ; Uložíme pøichozí bit do C a rotací jej dostaneme do EBYTE - takto zopakujem 8 krát pro celý byte
CALL @i2c_high_scl
BTFSS SDA
GOTO $+3
BSF STATUS,C
GOTO $+2
BCF STATUS,C
CALL @i2c_low_scl
RRF EBYTE,1
DECFSZ rot,1
GOTO i2c_in_byte_rot
RETLW 0
;---------------------------------------------------------
; Odešle 1 byt (promìnná EBYTE)
@i2c_out_byte
MOVLW 8
MOVWF rot
i2c_out_byte_rot ; Rotací EBYTE pøes Carry Flag odešleme postupnì všechny bity
RRF EBYTE,1
BTFSS STATUS,C
GOTO $+3
CALL @i2c_high_sda
GOTO $+2
CALL @i2c_low_sda
CALL @i2c_high_scl
CALL @i2c_low_scl
DECFSZ rot,1
GOTO i2c_out_byte_rot
CALL @i2c_high_sda
RETLW 0
;---------------------------------------------------------
@i2c_nack
CALL @i2c_high_sda
CALL @i2c_high_scl
CALL @i2c_low_scl
RETLW 0
@i2c_ack
CALL @i2c_low_sda
CALL @i2c_high_scl
CALL @i2c_low_scl
;CALL @i2c_high_sda
RETLW 0
@i2c_start
CALL @i2c_low_scl
CALL @i2c_high_sda
CALL @i2c_high_scl
CALL @i2c_low_sda
CALL @i2c_low_scl
RETLW 0
@i2c_stop
CALL @i2c_low_scl
CALL @i2c_low_sda
CALL @i2c_high_scl
CALL @i2c_high_sda
CALL @i2c_low_scl
RETLW 0
@i2c_high_sda
BSF STATUS,RP0 ; Banka 1
BSF SDADIR ; SDA vstup
BCF STATUS,RP0 ; Banka 0
CALL @delay_50us
RETLW 0
@i2c_low_sda
BCF SDA ; SDA = 0
BSF STATUS,RP0 ; Banka 1
BCF SDADIR ; SDA výstup
BCF STATUS,RP0 ; Banka 0
CALL @delay_50us
RETLW 0
@i2c_high_scl
BSF STATUS,RP0 ; Banka 1
BSF SCLDIR ; SCL vstup
BCF STATUS,RP0 ; Banka 0
CALL @delay_50us
RETLW 0
@i2c_low_scl
BCF SCL ; SCL = 0
BSF STATUS,RP0 ; Banka 1
BCF SCLDIR ; SCL výstup
BCF STATUS,RP0 ; Banka 0
CALL @delay_50us
RETLW 0
@delay_50us
MOVLW 16
MOVWF cd1
DECFSZ cd1,1
GOTO $-1
RETLW 0
Pro zápis pak používám:
Kód: Vybrat vše
CALL @i2c_start
; Device Address
MOVLW B'1010000'
MOVWF EBYTE
CALL @i2c_out_byte
CALL @i2c_nack
; First Word Address
MOVLW H'00'
MOVWF EBYTE
CALL @i2c_out_byte
CALL @i2c_nack
; Second Word Address (EADR adresa pro zápis)
MOVF EADR,W
MOVWF EBYTE
CALL @i2c_out_byte
CALL @i2c_nack
; Data
MOVLW H'88'
MOVWF EBYTE
CALL @i2c_out_byte
CALL @i2c_nack
CALL @i2c_stop
Kód: Vybrat vše
CALL @i2c_start
; Device Address
MOVLW B'1010000'
MOVWF EBYTE
CALL @i2c_out_byte
CALL @i2c_nack
; First Word Address
MOVLW H'00'
MOVWF EBYTE
CALL @i2c_out_byte
CALL @i2c_nack
; Second Word Address
MOVF EADR,W
MOVWF EBYTE
CALL @i2c_out_byte
CALL @i2c_nack
CALL @i2c_start
; Device Address
MOVLW B'1010001'
MOVWF EBYTE
CALL @i2c_out_byte
CALL @i2c_nack
CALL @i2c_in_byte
CALL @i2c_stop