Searching \ for 'I2C communications problems on PIC - please help!' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/i2cs.htm?key=i2c
Search entire site for: 'I2C communications problems on PIC - please help!'.

Truncated match.
PICList Thread
'I2C communications problems on PIC - please help!'
1997\05\29@031213 by Mark Hitchings

flavicon
picon face
Hi,
I am trying to perform I2C communications between PICs and I am having a
little trouble. I have written and tested code to perform transmission of
data by a master PIC which works perfectly well. I know that it is working
because I have viewed the bus output from the master on a CRO and the signal
checks out perfectly. The start bit, slave address(b'10100110'), data byte
and stop bit are all sent correctly on the SDA line. The clock is generated
on the SCL line correctly too. I can see however that the receiver which is
configured in slave mode does not send an acknowledge after the address
byte. After testing, I know that the receiving PIC is not generating a
SSPBUF buffer full interrupt. Clearly the receiving PIC is not recognising
the address sent over the I2C bus and therefore is not generating an
interrupt. The signal on the bus shows the transmitting master PIC is
sending the address of the receiver O.K. but the receiver does not match
this. It could be that I am not initialising the SSP module in the receiver
correctly and was wondering if anyone with experience in this area could
take a look at the code below which is resident in the receiver and tell me
what is wrong. Basically the code does the following:
* Initialises the SSP module by setting 7 bit slave mode in SSPCON, stores
it's slave address in SSPADD (b'10100110')and enables the SSPBUF interrupt
* Waits in an infinite loop for the SSPBUF interrupt
* When the interrupt is serviced, the data byte read is written to PORTD

Any suggestions would be GREATLY appreciated,
Regards
Mark.

;******************************************************************
       list    P=16C74, F=INHX8M, n=66 ;8 BIT HEX., 66 LINE PAGE
       include<p16c74.inc>
       include<icsl_pic.h>

;CHECK THE TYPE OF RESET
       ORG     RESET_V
RESET
       BSF     STATUS,RP0      ;Bank 1
       GOTO    START           ;Yes...then start the program
;------------------------------------------------------------------
;interrupt Service Routines go here
;-----------------------------------------------------------------
       ORG     ISR_V
PER_INT_V
       CALL    PUSH
       BTFSC   PIR1,SSPIF      ;Is it an SSP interrupt
       CALL    IIC_INT ;YES, then service it
       CALL    POP
       RETFIE
;----------------------------------------------------------------
;Start of main code
;----------------------------------------------------------------
START
       BCF     STATUS, RP0     ;Cleared for bank 0
       CLRF    STATUS  ;Clear status flags
       CLRF    PIR1            ;Clear peripheral interrupt flags
;CLEAR PORTS' DATA LATCHES
       BCF     STATUS,RP0      ;Cleared for bank 0
       CLRF    PORTC
       CLRF    PORTD
;SET UP PORTS FOR I/O DIRECTION
       BSF     STATUS,RP0      ;Set for bank 1
       CLRF    TRISD           ;ALL OUTPUTS

       CALL    INIT_IIC        ;Initialise the IIC comms. bus
;-------------------------------------------------------------------
;MAIN LOOP
;-------------------------------------------------------------------
LOOP1
       BSF     PORTE,RE1       ;Wait for comms
       BCF     PORTE,RE1       ;Toggle PORTE(1) *TEST*
       GOTO    LOOP1
;-------------------------------------------------------------------
;SUBROUTINES
;-----------------------------------------------------------------
;INIT_IIC
; This routine initialises the IIC communications stuff
;-------------------------------------------------------------------
INIT_IIC
       CLRF    DATA_IN ;Clear the data input
       CLRF    IIC_FLAG        ;Clear error register
       CLRF    PORTC           ;Set SDA, SCL low when not in IIC tri-state

       MOVLW   B'00110110'     ;
       MOVWF   SSPCON  ;IIC 7 bit slave mode

       BSF     STATUS,RP0      ;Bank 1
       MOVLW   B'00001000'     ;
       MOVWF   PIE1            ;Enable SSP interrupt

       MOVLW   b'10100110'     ; MY SLAVE ADDRESS
       MOVWF   SSPADD  ;Store my slave address

       BSF     TRISC,SCL       ;Set SCL high (input)
       BSF     TRISC,SDA       ;Set SDA high (input)

       BCF     STATUS,RP0      ;Bank 0

       BCF     PIR1,SSPIF      ;Clear SSP interrupt flag
       MOVLW   B'11000000'     ;Enable interrupts
       MOVWF   INTCON

       RETURN
;-------------------------------------------------------------
;IIC_INT
; The IIC interrupt service routine
;---------------------------------------------------------------
IIC_INT
       BCF     PIR1,SSPIF      ;Clear SSP interrupt
       BSF     STATUS,RP0      ;BANK 1
       BTFSS   SSPSTAT,BF      ;Check Buffer Full Flag
       GOTO    INT_OUT ;No data received, so exit
       BCF     STATUS,RP0      ;BANK 0
       MOVF    SSPBUF,W        ;Get I2C data
       BSF     STATUS,RP0      ;BANK 1
       BTFSS   SSPSTAT,DA      ;If Address received last...
       GOTO    INT_OUT ;  exit without saving it
       BCF     STATUS,RP0      ;Otherwise save data received
       MOVWF   DATA_IN ;Store the input data
       MOVWF   PORTD           ;Display on PORT D
INT_OUT
       BSF     STATUS,RP0      ;BANK 1
       BSF     PIE1,SSPIE      ;Re-enable SSP interrupt
       BCF     STATUS,RP0      ;BANK 0

       RETURN
;----------------------------------------------------------------
;PUSH
;----------------------------------------------------------------
PUSH
       MOVWF   TEMP_W  ;Save W register
       SWAPF   STATUS,W        ;Get STATUS register
       BCF     STATUS,RP0      ;Bank 0
       MOVWF   TEMP_STAT       ;Save STATUS register
       RETURN
;------------------------------------------------------------------
;POP
;------------------------------------------------------------------
POP
       SWAPF   TEMP_STAT,W     ;Restore STATUS register
       MOVWF   STATUS
       SWAPF   TEMP_W,1
       SWAPF   TEMP_W,W        ;Restore W register
       RETURN
;------------------------------------------------------------------
;END OF PROGRAM
;------------------------------------------------------------------
       ORG     PMEM_END        ;End of program memory
       END






----------------------------------------------------------------------
Mark Hitchings
R&D Engineer
Intelligent Control Systems Laboratory
School of Microelectronic Engineering
Griffith University, Nathan, Qld. 4111
ph: +61 7 3875 5067
fax: +61 7 3875 5384
email: spam_OUTmhitchinTakeThisOuTspamme.gu.edu.au
----------------------------------------------------------------------

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