Searching \ for '16Cxx I2C slave code request' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/i2cs.htm?key=i2c
Search entire site for: '16Cxx I2C slave code request'.

Truncated match.
PICList Thread
'16Cxx I2C slave code request'
1998\02\12@000902 by Rick Farmer

picon face
I've checked the archive and found a few good pointers on using the SSP in
I2C slave mode but I haven't found any example or boiler plate code. Anyone
have a pointer? Reinventing and debugging the wheel not my idea of fun. BTW
if anyone would like ANSI std CRC-16 code for 12c5xx and 16cxx, I've got a
nice fast table driven implementation.

Rick Farmer             |  2700 Croton Rd. #6-15
Electrical Engineer     |  Melbourne, Fl. 32935
spam_OUTrfarmerTakeThisOuTspammindspring.com  |  407-757-5006

1998\02\12@035135 by Thomas Magin

flavicon
face
part 0 3863 bytes
> I've checked the archive and found a few good pointers on using the SSP in
>I2C slave mode but I haven't found any example or boiler plate code. Anyone
>have a pointer? Reinventing and debugging the wheel not my idea of fun. BTW
>if anyone would like ANSI std CRC-16 code for 12c5xx and 16cxx, I've got a
>nice fast table driven implementation.

Hi,

have a look at the attachment. It's written for a 3-byte access (command,
data, checksum) but it should be easy to adapt it for your purpose.

Regards

Thomas
=8-)


;***************************************************************************
;*********** ISR: Interrupt Service Routine MAIN ***************************
;***************************************************************************

ISR     clrwdt
       bcf     INTCON,GIE      ; disable all interrupts

       PUSH
       btfsc   PIR1,SSPIF      ;
       call    I2C             ; I2C-Service
       POP

       bsf     INTCON,GIE      ; enable all interrupts
       retfie


;***************************************************************************
;            I2C: ISR-I2C-Unit
;***************************************************************************

I2C     bcf     PIR1,SSPIF      ; Clear SSP Interrupt
       bsf     STATUS,RP0      ; switch to Bank1

       btfss   SSPSTAT,DA_     ; If Address were received last
       goto    access          ;  decode next access
       btfsc   PS,I2C_RW       ; Data were received
       goto    rd_dat          ; master has read data
       goto    wr_dat          ; master wrote data

access  btfsc   SSPSTAT,RW_     ;
       goto    rd_adr          ; master read access will follow
       goto    wr_adr          ; master write access will follow

rd_dat  bcf     STATUS,RP0      ; switch to Bank0
       movf    TXCHECK,W       ; load Checksum
       movwf   SSPBUF          ;  in I2C-Register
       bsf     SSPCON,CKP      ; enable serial clock
       return                  ; data was read by master

wr_dat  bcf     STATUS,RP0      ; switch to Bank0
       movf    SSPBUF,W        ; Get I2C data
       movwf   RXBUF           ;  store it in RXBUF
       goto    sort_rx         ; result in RXBUF will be sorted

rd_adr  bsf     PS,I2C_RW       ; copy RW_-Bit to PS
       bcf     STATUS,RP0      ; switch to Bank0
       movf    TXDATA,W        ; load DATA
       movwf   SSPBUF          ;  in I2C-Register
       bsf     SSPCON,CKP      ; enable serial clock
       return                  ; data will be read by master

wr_adr  bcf     PS,I2C_RW       ; copy RW_-Bit to PS
       bcf     STATUS,RP0      ; switch to Bank0
       movf    SSPBUF,W        ; read SSPBUF in order to clear BF
       return                  ; data will be written by master


;***************************************************************************
;            INIT: Init Peripheral Functions and Ports
;***************************************************************************

       bsf     STATUS,RP0      ; switch to Bank1

       bsf     PIE1,3          ; enable I2C interrupt

       movlw   0x42            ; I2C slave address set to $42
       movwf   SSPAD           ;

       bcf     STATUS,RP0      ; switch to Bank0

       movlw   B'00110110'     ; I2C 7Bit slave mode
       movwf   SSPCON          ;

       movlw   B'11000000'     ; enable peripheral
       movwf   INTCON          ;  and global interrrupt

**********************************************************
* Thomas Magin                  FON:   ++49-761-4543-489 *
* marquette-Hellige GmbH        FAX:                -507 *
* Emergency Systems             email: .....maginKILLspamspam@spam@hellige.de  *
* Munzinger Str. 3                                       *
* D-79111 Freiburg / Germany                             *
**********************************************************

1998\02\12@183712 by Dan Walkowski

flavicon
face
I agree.  some boilerplate for i2c slave would be helpful, if anyone has
any.

Thanks,
Dan

1998\02\13@070106 by Thomas Magin

flavicon
face
At 15:36 12.02.1998 -0800, you wrote:
>I agree.  some boilerplate for i2c slave would be helpful, if anyone has
>any.

OK,

what do you think about this one:


;***************************************************************************
;*********** ISR: Interrupt Service Routine MAIN ***************************
;***************************************************************************

ISR     clrwdt
       bcf     INTCON,GIE      ; disable all interrupts

       PUSH
       btfsc   PIR1,SSPIF      ;
       call    I2C             ; I2C-Service
       POP

       bsf     INTCON,GIE      ; enable all interrupts
       retfie


;***************************************************************************
;            I2C: ISR-I2C-Unit
;***************************************************************************

I2C     bcf     PIR1,SSPIF      ; Clear SSP Interrupt
       bsf     STATUS,RP0      ; switch to Bank1

       btfss   SSPSTAT,DA_     ; If Address were received last
       goto    access          ;  decode next access
       btfsc   PS,I2C_RW       ; Data were received
       goto    rd_dat          ; master has read data
       goto    wr_dat          ; master wrote data

access  btfsc   SSPSTAT,RW_     ;
       goto    rd_adr          ; master read access will follow
       goto    wr_adr          ; master write access will follow

rd_dat  bcf     STATUS,RP0      ; switch to Bank0
       movf    TXCHECK,W       ; load Checksum
       movwf   SSPBUF          ;  in I2C-Register
       bsf     SSPCON,CKP      ; enable serial clock
       return                  ; data was read by master

wr_dat  bcf     STATUS,RP0      ; switch to Bank0
       movf    SSPBUF,W        ; Get I2C data
       movwf   RXBUF           ;  store it in RXBUF
       goto    sort_rx         ; result in RXBUF will be sorted

rd_adr  bsf     PS,I2C_RW       ; copy RW_-Bit to PS
       bcf     STATUS,RP0      ; switch to Bank0
       movf    TXDATA,W        ; load DATA
       movwf   SSPBUF          ;  in I2C-Register
       bsf     SSPCON,CKP      ; enable serial clock
       return                  ; data will be read by master

wr_adr  bcf     PS,I2C_RW       ; copy RW_-Bit to PS
       bcf     STATUS,RP0      ; switch to Bank0
       movf    SSPBUF,W        ; read SSPBUF in order to clear BF
       return                  ; data will be written by master


;***************************************************************************
;            INIT: Init Peripheral Functions and Ports
;***************************************************************************

       bsf     STATUS,RP0      ; switch to Bank1

       bsf     PIE1,3          ; enable I2C interrupt

       movlw   0x42            ; I2C slave address set to $42
       movwf   SSPAD           ;

       bcf     STATUS,RP0      ; switch to Bank0

       movlw   B'00110110'     ; I2C 7Bit slave mode
       movwf   SSPCON          ;

       movlw   B'11000000'     ; enable peripheral
       movwf   INTCON          ;  and global interrrupt


Actually it's for a 3 byte transmission, consisting of command, data and
checksum. But it should be easy to adapt it to any purpose.

So long

Thomas
=8-)

**********************************************************
* Thomas Magin                  FON:   ++49-761-4543-489 *
* marquette-Hellige GmbH        FAX:                -507 *
* Emergency Systems             email: maginspamKILLspamhellige.de  *
* Munzinger Str. 3                                       *
* D-79111 Freiburg / Germany                             *
**********************************************************

More... (looser matching)
- Last day of these posts
- In 1998 , 1999 only
- Today
- New search...