On Mon, 5 Jan 2004 19:06:44 -0500, Bob Blick wrote on Re: [PIC:] Pic as an i2c slave: >Sorry I forgot to note that all the RA3 =3D 1, i2cticker++, etc were all >just for diagnostics at the time I wrote it, you can remove them. > >-Bob Thanks indeed Bob for your friendly answer, I'll study this code carefully in the evening and compare it to my own implementation of the same state machine, whose origin is Microchip's AN734 application note in one of its numerous (3 I think) avatars. My hope (not much of it though given the time I have spent digging that problem) is to find a discrepancy between yours and my own code (and microchip's printed example, which is known not to be working as messages archived on this very list show). If I do not find anything significant, then I'll have to work on the assumption that the routines I use (see below) have a flaw. Looking at them and at the asm code the compiler provides, they seem to be correct though... But this does not prove a thing at my point... '*********************************************** '* Name : INT_CTRL.BAS * '* Author : Tim Box * '* Notice : Copyright (c) 2002 TJBSYSTEMS * '* : All Rights Reserved * '* Date : 28-Sep-02 * '* Version : 1.0 * '* Notes : * '* : * '*********************************************** '*********************************************** '* '* Declare variables '* '*********************************************** wsave VAR BYTE $20 SYSTEM =20 ' Save location for the W register if in bank0 wsave1 VAR BYTE $A0 SYSTEM =20 ' Save location for the W register if in bank1 wsave2 VAR BYTE $120 SYSTEM =20 ' Save location for the W register if in bank2 wsave3 VAR BYTE $1A0 SYSTEM =20 ' Save location for the W register if in bank3 ssave VAR BYTE Bank0 SYSTEM =20 ' Save location for the STATUS register psave VAR BYTE Bank0 SYSTEM =20 ' Save location for the PCLATH register fsave VAR BYTE Bank0 SYSTEM =20 ' Save location for the FSR register =20 ' PBP VARS TO SAVE R0_2 var WORD BANK0 =20 R1_2 VAR WORD BANK0 R2_2 VAR WORD BANK0 R3_2 VAR WORD BANK0 R4_2 VAR WORD BANK0 R5_2 VAR WORD BANK0 R6_2 VAR WORD BANK0 R7_2 VAR WORD BANK0 R8_2 VAR WORD BANK0 FLAGS_2 VAR BYTE BANK0 GOP_2 VAR BYTE BANK0 RM1_2 VAR BYTE BANK0 RM2_2 VAR BYTE BANK0 RR1_2 VAR BYTE BANK0 RR2_2 VAR BYTE BANK0 'T1_2 VAR BYTE BANK0 'T2_2 VAR BYTE BANK0 =20 'DEBUG_ADDRESS_2 VAR BYTE BANK0 'DEBUG_STACK_2 VAR BYTE BANK0 DEFINE INTHAND INT_CODE =20 'Tell PBP Where your code starts on an interrupt GOTO OVER_INT_CODE asm INT_CODE IF (CODE_SIZE <=3D 2) movwf wsave =20 ; copy W to wsave register swapf STATUS,W =20 ; swap status reg to be saved into W clrf STATUS =20 ; change to bank 0 regardless of current bank movwf ssave =20 ; save status reg to a bank 0 register movf PCLATH,w =20 ; move PCLATH reg to be saved into W reg movwf psave =20 ; save PCLATH reg to a bank 0 register EndIF movf FSR,W =20 ; move FSR reg to be saved into W reg movwf fsave =20 ; save FSR reg to a bank 0 register MOVF R0,W MOVWF _R0_2 MOVF R0 + 1,W MOVWF _R0_2 + 1=20 =20 MOVF R1,W MOVWF _R1_2 =20 MOVF R1 + 1,W MOVWF _R1_2 + 1 MOVF R2,W MOVWF _R2_2=20 MOVF R2 + 1,W MOVWF _R2_2 + 1 =20 MOVF R3,W MOVWF _R3_2 MOVF R3 + 1,W MOVWF _R3_2 + 1 =20 MOVF R4,W MOVWF _R4_2 MOVF R4 + 1,W MOVWF _R4_2 + 1 =20 MOVF R5,W MOVWF _R5_2 MOVF R5 + 1,W MOVWF _R5_2 + 1 =20 MOVF R6,W MOVWF _R6_2 MOVF R6 + 1,W MOVWF _R6_2 + 1 =20 =20 MOVF R7,W MOVWF _R7_2 MOVF R7 + 1 ,W MOVWF _R7_2 + 1=20 =20 MOVF R8,W MOVWF _R8_2 MOVF R8 + 1 ,W MOVWF _R8_2 + 1=20 =20 IFDEF T1 MOVF T1,W MOVWF _T1_2 =20 ENDIF IFDEF T2 MOVF T2,W MOVWF _T2_2 =20 ENDIF IFDEF FLAGS MOVF FLAGS,W MOVWF _FLAGS_2 =20 ENDIF IFDEF GOP MOVF GOP,W MOVWF _GOP_2 =20 ENDIF IFDEF RM1 MOVF RM1,W MOVWF _RM1_2 =20 ENDIF IFDEF RM2 MOVF RM2,W MOVWF _RM2_2 =20 ENDIF IFDEF RR1 MOVF RR1,W MOVWF _RR1_2 =20 ENDIF IFDEF RR2 MOVF RR2,W MOVWF _RR2_2 =20 ENDIF IFDEF DEBUG_ADDRESS MOVF DEBUG_ADDRESS,W MOVWF _DEBUG_ADDRESS_2 =20 ENDIF IFDEF DEBUG_STACK MOVF DEBUG_STACK,W MOVWF _DEBUG_STACK_2 =20 ENDIF endasm goto MY_INT_HANDLER INT_RETURN: ASM MOVF _R0_2,W MOVWF R0 MOVF _R0_2 + 1,W MOVWF R0 + 1 =20 MOVF _R1_2,W MOVWF R1 MOVF _R1_2 + 1,W MOVWF R1 + 1 =20 MOVF _R2_2,W MOVWF R2 MOVF _R2_2 + 1,W MOVWF R2 + 1 =20 MOVF _R3_2,W MOVWF R3 MOVF _R3_2 + 1,W MOVWF R3 + 1 =20 MOVF _R4_2,W MOVWF R4 MOVF _R4_2 + 1,W MOVWF R4 + 1 =20 MOVF _R5_2,W MOVWF R5 MOVF _R5_2 + 1,W MOVWF R5 + 1 =20 MOVF _R6_2,W MOVWF R6 MOVF _R6_2 + 1,W MOVWF R6 + 1 =20 MOVF _R7_2,W MOVWF R7 MOVF _R7_2 + 1,W MOVWF R7 + 1 =20 MOVF _R8_2,W MOVWF R8 MOVF _R8_2 + 1,W MOVWF R8 + 1 =20 IFDEF FLAGS MOVF _FLAGS_2,W MOVWF FLAGS =20 ENDIF IFDEF GOP MOVF _GOP_2,W MOVWF GOP EndIF IFDEF RM1 MOVF _RM1_2,W MOVWF RM1 =20 ENDIF IFDEF RM2=20 MOVF _RM2_2,W MOVWF RM2 =20 ENDIF IFDEF RR1 MOVF _RR1_2,W MOVWF RR1 =20 ENDIF IFDEF RR2 MOVF _RR2_2,W MOVWF RR2 =20 ENDIF IFDEF T1=20 MOVF _T1_2,W MOVWF T1 =20 ENDIF IFDEF T2 MOVF _T2_2,W MOVWF T2 ENDIF=20 IFDEF DEBUG_ADDRESS MOVF _DEBUG_ADDRESS_2 ,W MOVWF DEBUG_ADDRESS ENDIF IFDEF DEBUG_STACK MOVF _DEBUG_STACK_2,W MOVWF DEBUG_STACK =20 ENDIF MOVF fsave,W =20 ; Restore the FSR reg=20 MOVWF FSR Movf psave,w =20 ; Restore the PCLATH reg Movwf PCLATH swapf ssave,w =20 ; Restore the STATUS reg =09 movwf STATUS swapf wsave,f swapf wsave,w =20 ; Restore W reg Retfie =20 ; Exit the interrupt routine=09 =20 ENDASM OVER_INT_CODE: * Xrobert.soubie@free.frX (veuillez supprimer les "X") * http://www.astrosurf.com/soubie * Au royaume des aveugles, les borgnes sont mal vus... - P.Dac -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu