Hi Vasile,
Before testing this I gave this some more thought and had a short look at the assembly file.
The issue is that as soon at I do any IIC ibrary call from an interrupt routine, all these routines become 'interrupt routines' if you know what I mean. I think that means that these routines can no longer be called from a non-interrupt location like the main
program.
For example a non-interrupt routine to transmit something over the IIC looks like this:
; 102 function i2c_transmit_byte(byte in data) return bit is
l_i2c_transmit_byte
movlb 0
movwf v___data_80
; 104 PIR1_SSPIF = false ; clear pending flag
bcf v_pir1, 3 ; pir1_ssp1if
; 105 sspbuf = data ; write data
movf v___data_80,w
movlb 4
movwf v_ssp1buf
; 108 while ! PIR1_SSPIF loop end loop
l__l524
movlb 0
btfsc v_pir1, 3 ; pir1_ssp1if
goto l__l525
goto l__l524
l__l525
; 113 if SSPCON2_ACKSTAT == low then
movlb 4
btfsc v_ssp1con2, 6 ; ssp1con2_ackstat
goto l__l528
; 114 return true -- okay
movlb 0
bsf v__pic_temp, 0 ; _pic_temp
return
But if you do a call to the same IIC procedure from an interrupt the code becomes this:
; 102 function i2c_transmit_byte(byte in data) return bit is
l_i2c_transmit_byte
incf v__ri2c_transmit_byte,f
decfsz v__ri2c_transmit_byte,w
goto l__l712
movlp HIGH l__l713
goto l__l713
l__l712
movf v__pic_stkptr+1,w
movwf v__fsr0h
movf v__pic_stkptr,w
movwf v__fsr0l
decf v__pic_stkptr,f
decf v__fsr0l,f
movf v__fi2c_transmit_byte,w
movwf v__ind
l__l713
movf v__pic_temp,w
movwf v___data_80
; 104 PIR1_SSPIF = false ; clear pending flag
bcf v_pir1, 3 ; pir1_ssp1if
; 105 sspbuf = data ; write data
movf v___data_80,w
movlb 4
movwf v_ssp1buf
; 108 while ! PIR1_SSPIF loop end loop
l__l524
movlp HIGH l__l525
movlb 0
btfsc v_pir1, 3 ; pir1_ssp1if
goto l__l525
goto l__l524
l__l525
; 113 if SSPCON2_ACKSTAT == low then
movlb 4
btfsc v_ssp1con2, 6 ; ssp1con2_ackstat
goto l__l528
; 114 return true -- okay
movlb 0
bsf v__pic_temp, 0 ; _pic_temp
goto l__l523
; 115 else
l__l528
; 116 sspcon1_sspen = false;
bcf v_ssp1con1, 5 ; ssp1con1_sspen
; 117 sspcon1_sspen = true;
bsf v_ssp1con1, 5 ; ssp1con1_sspen
; 119 return false -- no response
movlb 0
bcf v__pic_temp, 0 ; _pic_temp
; 120 end if
; 121 end function
l__l523
decfsz v__ri2c_transmit_byte,f
goto l__l715
return
l__l715
movf v__pic_stkptr+1,w
movwf v__fsr0h
movf v__pic_stkptr,w
movwf v__fsr0l
movf v__ind,w
movwf v__fi2c_transmit_byte
incf v__fsr0l,w
movwf v__pic_stkptr
l__l714
return
I think it cannot be mixed. The only solution I can think of is making separate routines that access the IIC hardware registers directly without a call to any other - common - routine.
Kind regards,
Rob