Hi all, I am using PIC16F88 as an I2C slave. I have attached the code that I used. From the Microchip MPLAB ICD 2, I find that I am able to detect the start and stop conditions. But I find that SSPSTAT is not getting set. The program is getting stuck in the "gnb" loop. From the Microchip ICD2, I can see that SSPSTAT and SSPSTAT get set after the Start and Stop condictions. But not the BF bit. Nothing changes even if i enable the interrupts. Probably the address was not getting matched. I am using BL233 to mimic a master. Please let me know what mistake I am doing.
Thanking you, Mallik.
processor 16f88 include p16f88.inc __CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_ON & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_OFF & _WDT_OFF & _HS_OSC ; org 0x00 nop ;required for In-Circuit Debugger ; ; initialize I/O ; bsf STATUS,RP0 movlw b'11010010' ;RB0,RB2,RB3,RB5 are outputs movwf TRISB bcf STATUS,RP0 ; ; Initialize the I2C ; clrf SSPCON movlw 0x36 ;SSPEN + CKP + i2c slave mode 7 bit movwf SSPCON
movlw 0x38 ;slave address for flash loader bsf STATUS,RP0 movwf SSPADD
clrf SSPSTAT
; bcf INTCON,GIE ;interrupts off (for now) bsf INTCON,GIE ;interrupts on (for now) banksel PIE1 ; Enable interrupts bsf PIE1,SSPIE clrf STATUS
test: call gnb goto test ; ; Get Next Byte from I2C ; ; exit: C == 1 if Start condition was last received ; C == 0 if Stop condiction received. ; Z == 1 if Data was received ; gnb: bsf STATUS,RP0 btfss SSPSTAT,BF ;check buffer full flag goto gnb ;loop if byte not ready
btfss SSPSTAT,5 bsf STATUS,Z
bcf STATUS,RP0 bcf PIR1,SSPIF ;clear interrupt flag
movf SSPBUF,W ;get byte
btfsc SSPSTAT,S ;check start/repeated start condition goto gnb2 ;jump if start received
return ; ; get here if a START was received. ; gnb2: bsf STATUS,C return
end