Hi, I've been trying to comunicate two 16c74 via a I2C bus,but so long,I haven't had any success.Thanks to Lee Hewitt's mail,I learnt I needed to implement master in software,so I took the code from an578 (I2c in a multimaster environment).The code works fine,I took the slave part (interrupt driven) away,and disabled ssp interrupts ,since the master is only intended to transmit two bytes (S-slaveadd-r/w , 2nd byte , stop),it doesn't use interrupts at all. I simulated it,and worked OK. Then I wrote the code for the slave 16c74,this time enabling ssp interrupts. The slave is intended to receive a byte of data to update CCPRL1 register, change the duty cycle of a 10 khz PWM,and put the received data on PORT_B, so I can check it with a volt-meter.I put in some code to turn on a led on D7 for 300 ms every time the SSP interrupt is touched off. When master transmits,the led blinks,indicating that SSP interruption actually takes place,put no transmision is accomplished,and when I check the master for the error type it returns err3,NO ACKNOWLEDGEMENT (no handshaking). The bus is pulled up by 4,7 kohm resistors.Then I thought,may be that's too much,and tried 2,2 kohm,but nothing so far. Could any of you,please check this piece of code and tell me what am I forgetting?Or If any of you has done this before,could you show me how to do it? Thank you. ;********************************************************************** LIST P=16C74, F=INHX8M ;***************************************************** include INCLUDE "PICREG.EQU" INCLUDE "PICMACRO.H" ; RP0 EQU .5 GIE EQU .7 SCL EQU .3 SDA EQU .4 PWMDUTY EQU 0xA2 ; push macro movwf WBuffer ;save w reg in Buffer swapf WBuffer, F ;swap it swapf STATUS,w ;get status movwf StatBuffer ;save it endm ; pop macro swapf StatBuffer,w ;restore status movwf STATUS ; / swapf WBuffer,w ;restore W reg endm ; org 0 goto RESET ;skip over interrupt vector ; org 4 ;It is always a good practice to save and restore the w reg, ;and the status reg during a interrupt. push call ISR pop retfie ; ISR BCF INTCON,GIE ;DISABLE GLOBAL INTERRUPTS BTFSC INTCON,GIE GOTO ISR CLRWDT goto ServiceInt ;yes then service return ServiceInt BSF PORT_D,7 ;PRENDER LED EN d7 bcf PIR1,SSPIF ; Clear SSP interrupt bsf STATUS,RP0 btfss SSPSTAT,BF ; Check Buffer Full Flag goto IntOut ; No data received, so exit bcf STATUS,RP0 movf SSPBUF,W ; Get I2C data bsf STATUS,RP0 btfss SSPSTAT,DA ; If Address received last... goto IntOut ; exit without saving it MOVWF PWMDUTY ; CALL PWMCHG ;UPDATE PWMDUTYCYCLE bcf STATUS,RP0 movwf PORT_B ; Display received data on LEDs IntOut bsf STATUS,RP0 bsf PIE1,SSPIE ; Re-enable SSP interrupt bcf STATUS,RP0 clrf LOWER ;RETARDO APROX 300 MILISEG clrf UPPER loop nop nop decfsz LOWER goto loop decfsz UPPER goto loop bcf PORT_D,7 ;APAGAR EL LED RETURN ;************************************************************* ;CLEARMEMORY clears all ram registers from 20h to 7Fh and from ;A0 to FFh ;************************************************************* ; CLEARMEMORY bcf STATUS,RP0 movlw 20h movwf FSR NEXT clrf INDF incf FSR,F btfss FSR,7 goto NEXT bsf STATUS,RP0 movlw 0xA0 movwf FSR NEXT1 clrf INDF incfsz FSR,F goto NEXT1 bcf STATUS,RP0 return ; ;*************************************************************** ; InitPorts bcf STATUS,RP0 ;page 0 clrf PORT_A clrf PORT_B clrf PORT_C clrf PORT_D bsf STATUS,RP0 ;select pg 1 movlw 0xff ;make RA0-3 digital I/O movwf ADCON1 ; / clrf TRISA ;make RA0-4 outputs clrf TRISB ;make RB0-7 outputs clrf TRISD clrf TRISC bcf STATUS,RP0 ;select page 0 clrf PORT_A ;make all outputs low clrf PORT_B ; / clrf PORT_D ; return ;***************************************************** ;RUTINA PARA PWM ,10 Khz ,DUTYCYCLE EN A4 (A2 + 0002) ;TOMA VALORES DE 0 A 99,corresponde a ;***************************************************** ; PWMINI BCF INTCON,PEIE ;DESABLE PERIPHERAL BSF STATUS,RP0 ;INTERRUPTS MOVLW .99 ;PERIODO PARA 10 KHZ MOVWF PR2 ;DEFINE PERIODO = 100 uS MOVLW .50 MOVWF PWMDUTY BCF STATUS,RP0 MOVWF CCPR1L ;ARRANCA CON PWMDUTY 50% MOVLW B'00001100' ; MOVWF CCP1CON ;1100 ,DEFINE MODO PWM MOVLW B'00000100' ;TIMER2ON MOVWF T2CON ;TIMER2 ON RETURN PWMCHG ; BSF STATUS,RP0 ;ACTUALIZA PWM DUTYCYCLE MOVF PWMDUTY,W BCF STATUS,RP0 MOVWF CCPR1L RETURN ;************************************************************** RESET BSF STATUS,RP0 ;BANK1 BTFSC STATUS,4 ;WDT TIME OUT? GOTO START ;NO BCF STATUS,RP0 ;BANK0 GOTO WATCHDG ;WATCHDOG TIMER OVERFLOW START CALL CLEARMEMORY WATCHDG BCF STATUS,RP0 CLRWDT MOVLW .0 ; OPTION CLRF INTCON CALL InitPorts call PWMINI ;INICIALIZA PWM clrf PORT_C ; Set SDA, SCL low when not is tri-state movlw B'00111110' ; I2C 7 bit slave mode with master movwf SSPCON ; mode enabled bsf STATUS,RP0 ; Select page 1 movlw B'00001000' ; Enable SSP interrupt movwf PIE1 movlw b'10100010' ; Slave address (=A2) movwf SSPADD bsf TRISC,SCL ; Set SCL high bsf TRISC,SDA ; Set SDA high bcf STATUS,RP0 ; Select page 0 bcf PIR1,3 ; Clear SSP interrupt flag movlw B'11000000' ; Enable interrupts movwf INTCON LOOP1 CLRWDT ;WAIT FOR SSPINTERRUPT NOP GOTO LOOP1 END