Discussion:
[PIC] I2C Module on 18F67K40
Carey Fisher
2018-02-27 20:24:47 UTC
Permalink
I'm having a terrible time trying to get the I2C module on the 18F67K40 working. My test code is posted below. This code and the I2C module seem very simple so I must be missing something simple.
This code tries to read address 0000 of an attached 24LC512 EEPROM. I know the hardware is good because I can use Pic Basic Pro and read and write the EEPROM using I2C.
The code I'm using came off a forum on the Microchip Support website. It is "bullet proof". Ha.

I've put debugging statements in the code and what I've found is that the Interrupt flag, PIR3,SSP1IF, never gets asserted.

Any pointers would be greatly appreciated.


'i2ctest.pbp
'another try at reading I2C data from 24LC512

'Start Condition
'Control Byte for write
'High address byte
'Low address byte
'Start Condition
'Control Byte for read
'Read in data byte
'Return with NACK
'Stop Condition


asm
#define Memtop 0x10000 ;higest memory in the 18F67k40 processor
Startaddress = MemTop-800
SDA = 4
SCL = 3

ORG Startaddress

;***************************************************************
;
; 24LC256 I2C Single Byte Read Routines
;

;
;
_I2CTEST1
rcall I2CInit

;EE_RD
rcall I2CStrt ;send I2C START
movlw h'A6'
rcall I2CSend ;send device address (control byte)
movlw h'00'
rcall I2CSend ;send address hi byte
movlw h'00'
rcall I2CSend ;send address lo byte
rcall I2CStrt ;send I2C START
movlw h'A7'
rcall I2CSend ;send device address (control byte)
EE_R1
rcall I2CRcv ;receive mode (receive byte)
movwf _testbyte1
rcall I2CNack ;signal end of receive
rcall I2CStopp ;send STOP
return ;

;***************************************************************
;
; I2C primitives
;
; SSPADD = ((Fosc/I2Cclock)/4)-1 {formula from AN735}
;

I2CInit
bsf PIE3,SSP1IE ; enable the Interrupt flag, PIR3,SSP1IF
bsf TRISC,SCL ;
bsf TRISC,SDA ;
movlw b'00101000' ;SSPEN + 12C Master
movwf SSP1CON1 ;
movlw b'00000000' ;
movwf SSP1CON2 ;
movlw b'00000000' ;slew rate on for 400khz
movwf SSP1STAT ;
movlw d'13' ;(20000000/100000)-1/4
movwf SSP1ADD ;400khz using 20mhz xtal
return ;

I2CDebug
movf ssp1stat,0
movwf _testbyte1
movf ssp1con1,0
movwf _testbyte2
movf ssp1con2,0
movwf _testbyte3
movf ssp1con3,0
movwf _testbyte4
return

I2CWait
btfss PIR3,SSP1IF ;complete flag?
bra I2CWait ;no, wait
bcf PIR3,SSP1IF ;clear irq flag
return ;

I2CStrt
bsf SSP1CON2,SEN_SSP1CON2 ;send START condition
bra I2CWait ;

I2CStopp
bsf SSP1CON2,PEN ;send STOP condition
bra I2CWait ;

I2CSend
movwf SSP1BUF ;send byte
bra I2CWait ;

I2CRcv
btfsc SSP1STAT,R_W ;transmit complete?
bra I2CRcv ;no, wait
bsf SSP1CON2,RCEN ;receive enable
bcf PIR3,SSP1IF ;clear irq flag
rcall I2CWait ;
movf SSP1BUF,W ;
return ;

I2CAck
bcf SSP1CON2,ACKDT ;set ACK
bra I2CNack+2 ;

I2CNack
bsf SSP1CON2,ACKDT ;set NACK
bsf SSP1CON2,ACKEN ;send ACK or NACK
bra I2CWait ;

I2CRes
bsf SSP1CON2,RSEN ;send RESTART condition
bra I2CWait ;

endasm

Carey Fisher │ Director of Engineering
O +1 770-209-0012 x2031 │ F +1 770-209-0719
4295 Hamilton Mill Road │ Suite 100 │ Buford, GA 30518
www.omnimetrix.net



Tell us how we're doing! Click here to take our two-question survey.

     
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailm
Ray Haddad
2018-02-27 20:56:25 UTC
Permalink
Carey,

All other functions on those pins must be disabled in your header. Only
the SCL and SDA outputs can be enable. Refer to the spec sheet so set your
registers to disable those functions.

Ray
Post by Carey Fisher
I'm having a terrible time trying to get the I2C module on the 18F67K40
working. My test code is posted below. This code and the I2C module seem
very simple so I must be missing something simple.
This code tries to read address 0000 of an attached 24LC512 EEPROM. I know
the hardware is good because I can use Pic Basic Pro and read and write
the EEPROM using I2C.
The code I'm using came off a forum on the Microchip Support website. It
is "bullet proof". Ha.
I've put debugging statements in the code and what I've found is that the
Interrupt flag, PIR3,SSP1IF, never gets asserted.
Any pointers would be greatly appreciated.
'i2ctest.pbp
'another try at reading I2C data from 24LC512
'Start Condition
'Control Byte for write
'High address byte
'Low address byte
'Start Condition
'Control Byte for read
'Read in data byte
'Return with NACK
'Stop Condition
asm
#define Memtop 0x10000 ;higest memory in the 18F67k40 processor
Startaddress = MemTop-800
SDA = 4
SCL = 3
ORG Startaddress
;***************************************************************
;
; 24LC256 I2C Single Byte Read Routines
;
;
;
_I2CTEST1
rcall I2CInit
;EE_RD
rcall I2CStrt ;send I2C START
movlw h'A6'
rcall I2CSend ;send device address (control byte)
movlw h'00'
rcall I2CSend ;send address hi byte
movlw h'00'
rcall I2CSend ;send address lo byte
rcall I2CStrt ;send I2C START
movlw h'A7'
rcall I2CSend ;send device address (control byte)
EE_R1
rcall I2CRcv ;receive mode (receive byte)
movwf _testbyte1
rcall I2CNack ;signal end of receive
rcall I2CStopp ;send STOP
return ;
;***************************************************************
;
; I2C primitives
;
; SSPADD = ((Fosc/I2Cclock)/4)-1 {formula from AN735}
;
I2CInit
bsf PIE3,SSP1IE ; enable the Interrupt flag, PIR3,SSP1IF
bsf TRISC,SCL ;
bsf TRISC,SDA ;
movlw b'00101000' ;SSPEN + 12C Master
movwf SSP1CON1 ;
movlw b'00000000' ;
movwf SSP1CON2 ;
movlw b'00000000' ;slew rate on for 400khz
movwf SSP1STAT ;
movlw d'13' ;(20000000/100000)-1/4
movwf SSP1ADD ;400khz using 20mhz xtal
return ;
I2CDebug
movf ssp1stat,0
movwf _testbyte1
movf ssp1con1,0
movwf _testbyte2
movf ssp1con2,0
movwf _testbyte3
movf ssp1con3,0
movwf _testbyte4
return
I2CWait
btfss PIR3,SSP1IF ;complete flag?
bra I2CWait ;no, wait
bcf PIR3,SSP1IF ;clear irq flag
return ;
I2CStrt
bsf SSP1CON2,SEN_SSP1CON2 ;send START condition
bra I2CWait ;
I2CStopp
bsf SSP1CON2,PEN ;send STOP condition
bra I2CWait ;
I2CSend
movwf SSP1BUF ;send byte
bra I2CWait ;
I2CRcv
btfsc SSP1STAT,R_W ;transmit complete?
bra I2CRcv ;no, wait
bsf SSP1CON2,RCEN ;receive enable
bcf PIR3,SSP1IF ;clear irq flag
rcall I2CWait ;
movf SSP1BUF,W ;
return ;
I2CAck
bcf SSP1CON2,ACKDT ;set ACK
bra I2CNack+2 ;
I2CNack
bsf SSP1CON2,ACKDT ;set NACK
bsf SSP1CON2,ACKEN ;send ACK or NACK
bra I2CWait ;
I2CRes
bsf SSP1CON2,RSEN ;send RESTART condition
bra I2CWait ;
endasm
Carey Fisher │ Director of Engineering
O +1 770-209-0012 x2031 │ F +1 770-209-0719
4295 Hamilton Mill Road │ Suite 100 │ Buford, GA 30518
www.omnimetrix.net
Tell us how we're doing! Click here to take our two-question survey.
     
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.
Carey Fisher
2018-02-28 18:33:56 UTC
Permalink
Ray,

Thank you for the response.

I've set SSP1CON1.SSPEN to configure the pins. There are no analogs on PortC so no need to configure ANSELC. The port pin assignments default to the correct values at power on so no need to mess with the PPS registers.

What else needs to be done?

Carey Fisher

-----Original Message-----
From: piclist-***@mit.edu [mailto:piclist-***@mit.edu] On Behalf Of Ray Haddad
Sent: Tuesday, February 27, 2018 3:56 PM
To: Microcontroller discussion list - Public. <***@mit.edu>
Subject: Re: [PIC] I2C Module on 18F67K40

Carey,

All other functions on those pins must be disabled in your header. Only the SCL and SDA outputs can be enable. Refer to the spec sheet so set your registers to disable those functions.

Ray
Post by Carey Fisher
I'm having a terrible time trying to get the I2C module on the
18F67K40 working. My test code is posted below. This code and the I2C
module seem very simple so I must be missing something simple.
This code tries to read address 0000 of an attached 24LC512 EEPROM. I
know the hardware is good because I can use Pic Basic Pro and read and
write the EEPROM using I2C.
The code I'm using came off a forum on the Microchip Support website.
It is "bullet proof". Ha.
I've put debugging statements in the code and what I've found is that
the Interrupt flag, PIR3,SSP1IF, never gets asserted.
Any pointers would be greatly appreciated.
'i2ctest.pbp
'another try at reading I2C data from 24LC512
'Start Condition
'Control Byte for write
'High address byte
'Low address byte
'Start Condition
'Control Byte for read
'Read in data byte
'Return with NACK
'Stop Condition
asm
#define Memtop 0x10000 ;higest memory in the 18F67k40 processor
Startaddress = MemTop-800
SDA = 4
SCL = 3
ORG Startaddress
;***************************************************************
;
; 24LC256 I2C Single Byte Read Routines ;
;
;
_I2CTEST1
rcall I2CInit
;EE_RD
rcall I2CStrt ;send I2C START
movlw h'A6'
rcall I2CSend ;send device address (control byte)
movlw h'00'
rcall I2CSend ;send address hi byte
movlw h'00'
rcall I2CSend ;send address lo byte
rcall I2CStrt ;send I2C START
movlw h'A7'
rcall I2CSend ;send device address (control byte)
EE_R1
rcall I2CRcv ;receive mode (receive byte)
movwf _testbyte1
rcall I2CNack ;signal end of receive
rcall I2CStopp ;send STOP
return ;
;***************************************************************
;
; I2C primitives
;
; SSPADD = ((Fosc/I2Cclock)/4)-1 {formula from AN735} ;
I2CInit
bsf PIE3,SSP1IE ; enable the Interrupt flag, PIR3,SSP1IF
bsf TRISC,SCL ;
bsf TRISC,SDA ;
movlw b'00101000' ;SSPEN + 12C Master
movwf SSP1CON1 ;
movlw b'00000000' ;
movwf SSP1CON2 ;
movlw b'00000000' ;slew rate on for 400khz
movwf SSP1STAT ;
movlw d'13' ;(20000000/100000)-1/4
movwf SSP1ADD ;400khz using 20mhz xtal
return ;
I2CDebug
movf ssp1stat,0
movwf _testbyte1
movf ssp1con1,0
movwf _testbyte2
movf ssp1con2,0
movwf _testbyte3
movf ssp1con3,0
movwf _testbyte4
return
I2CWait
btfss PIR3,SSP1IF ;complete flag?
bra I2CWait ;no, wait
bcf PIR3,SSP1IF ;clear irq flag
return ;
I2CStrt
bsf SSP1CON2,SEN_SSP1CON2 ;send START condition
bra I2CWait ;
I2CStopp
bsf SSP1CON2,PEN ;send STOP condition
bra I2CWait ;
I2CSend
movwf SSP1BUF ;send byte
bra I2CWait ;
I2CRcv
btfsc SSP1STAT,R_W ;transmit complete?
bra I2CRcv ;no, wait
bsf SSP1CON2,RCEN ;receive enable
bcf PIR3,SSP1IF ;clear irq flag
rcall I2CWait ;
movf SSP1BUF,W ;
return ;
I2CAck
bcf SSP1CON2,ACKDT ;set ACK
bra I2CNack+2 ;
I2CNack
bsf SSP1CON2,ACKDT ;set NACK
bsf SSP1CON2,ACKEN ;send ACK or NACK
bra I2CWait ;
I2CRes
bsf SSP1CON2,RSEN ;send RESTART condition
bra I2CWait ;
endasm
Carey Fisher │ Director of Engineering O +1 770-209-0012 x2031 │ F +1
770-209-0719
4295 Hamilton Mill Road │ Suite 100 │ Buford, GA 30518
www.omnimetrix.net
Tell us how we're doing! Click here to take our two-question survey.
     
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listin
Ray Haddad
2018-02-28 19:42:20 UTC
Permalink
Carey,

Despite not expecting any analog signals, you still have to disable the
analog input to ensure that your I2C lines have the correct impedance. It
may seem illogical but that's the way the K series of PICs works.

Best,
Ray
Post by Carey Fisher
Ray,
Thank you for the response.
I've set SSP1CON1.SSPEN to configure the pins. There are no analogs on
PortC so no need to configure ANSELC. The port pin assignments default to
the correct values at power on so no need to mess with the PPS registers.
What else needs to be done?
Carey Fisher
-----Original Message-----
Sent: Tuesday, February 27, 2018 3:56 PM
Subject: Re: [PIC] I2C Module on 18F67K40
Carey,
All other functions on those pins must be disabled in your header. Only
the SCL and SDA outputs can be enable. Refer to the spec sheet so set your
registers to disable those functions.
Ray
Post by Carey Fisher
I'm having a terrible time trying to get the I2C module on the
18F67K40 working. My test code is posted below. This code and the I2C
module seem very simple so I must be missing something simple.
This code tries to read address 0000 of an attached 24LC512 EEPROM. I
know the hardware is good because I can use Pic Basic Pro and read and
write the EEPROM using I2C.
The code I'm using came off a forum on the Microchip Support website.
It is "bullet proof". Ha.
I've put debugging statements in the code and what I've found is that
the Interrupt flag, PIR3,SSP1IF, never gets asserted.
Any pointers would be greatly appreciated.
'i2ctest.pbp
'another try at reading I2C data from 24LC512
'Start Condition
'Control Byte for write
'High address byte
'Low address byte
'Start Condition
'Control Byte for read
'Read in data byte
'Return with NACK
'Stop Condition
asm
#define Memtop 0x10000 ;higest memory in the 18F67k40 processor
Startaddress = MemTop-800
SDA = 4
SCL = 3
ORG Startaddress
;***************************************************************
;
; 24LC256 I2C Single Byte Read Routines ;
;
;
_I2CTEST1
rcall I2CInit
;EE_RD
rcall I2CStrt ;send I2C START
movlw h'A6'
rcall I2CSend ;send device address (control byte)
movlw h'00'
rcall I2CSend ;send address hi byte
movlw h'00'
rcall I2CSend ;send address lo byte
rcall I2CStrt ;send I2C START
movlw h'A7'
rcall I2CSend ;send device address (control byte)
EE_R1
rcall I2CRcv ;receive mode (receive byte)
movwf _testbyte1
rcall I2CNack ;signal end of receive
rcall I2CStopp ;send STOP
return ;
;***************************************************************
;
; I2C primitives
;
; SSPADD = ((Fosc/I2Cclock)/4)-1 {formula from AN735} ;
I2CInit
bsf PIE3,SSP1IE ; enable the Interrupt flag, PIR3,SSP1IF
bsf TRISC,SCL ;
bsf TRISC,SDA ;
movlw b'00101000' ;SSPEN + 12C Master
movwf SSP1CON1 ;
movlw b'00000000' ;
movwf SSP1CON2 ;
movlw b'00000000' ;slew rate on for 400khz
movwf SSP1STAT ;
movlw d'13' ;(20000000/100000)-1/4
movwf SSP1ADD ;400khz using 20mhz xtal
return ;
I2CDebug
movf ssp1stat,0
movwf _testbyte1
movf ssp1con1,0
movwf _testbyte2
movf ssp1con2,0
movwf _testbyte3
movf ssp1con3,0
movwf _testbyte4
return
I2CWait
btfss PIR3,SSP1IF ;complete flag?
bra I2CWait ;no, wait
bcf PIR3,SSP1IF ;clear irq flag
return ;
I2CStrt
bsf SSP1CON2,SEN_SSP1CON2 ;send START condition
bra I2CWait ;
I2CStopp
bsf SSP1CON2,PEN ;send STOP condition
bra I2CWait ;
I2CSend
movwf SSP1BUF ;send byte
bra I2CWait ;
I2CRcv
btfsc SSP1STAT,R_W ;transmit complete?
bra I2CRcv ;no, wait
bsf SSP1CON2,RCEN ;receive enable
bcf PIR3,SSP1IF ;clear irq flag
rcall I2CWait ;
movf SSP1BUF,W ;
return ;
I2CAck
bcf SSP1CON2,ACKDT ;set ACK
bra I2CNack+2 ;
I2CNack
bsf SSP1CON2,ACKDT ;set NACK
bsf SSP1CON2,ACKEN ;send ACK or NACK
bra I2CWait ;
I2CRes
bsf SSP1CON2,RSEN ;send RESTART condition
bra I2CWait ;
endasm
Carey Fisher │ Director of Engineering O +1 770-209-0012 x2031 │ F +1
770-209-0719
4295 Hamilton Mill Road │ Suite 100 │ Buford, GA 30518
www.omnimetrix.net
Tell us how we're doing! Click here to take our two-question survey.
     
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/pic
Carey Fisher
2018-02-28 20:26:19 UTC
Permalink
What I meant was, there are no analog peripherals on PORTC so there is no ANSELC register.

The main problem I'm having with using the sample code is the Interrupt flag, PIR3,SSP1IF, never gets asserted. The SCL and SDA lines seem to act correctly when viewed on a scope but the code stops when waiting for the Interrupt flag, PIR3,SSP1IF, to get asserted.

Carey Fisher │ Director of Engineering
P 770-209-0012 ext. 2031
www.omnimetrix.net

-----Original Message-----
From: piclist-***@mit.edu [mailto:piclist-***@mit.edu] On Behalf Of Ray Haddad
Sent: Wednesday, February 28, 2018 2:42 PM
To: Microcontroller discussion list - Public. <***@mit.edu>
Subject: RE: [PIC] I2C Module on 18F67K40

Carey,

Despite not expecting any analog signals, you still have to disable the analog input to ensure that your I2C lines have the correct impedance. It may seem illogical but that's the way the K series of PICs works.

Best,
Ray
Post by Carey Fisher
Ray,
Thank you for the response.
I've set SSP1CON1.SSPEN to configure the pins. There are no analogs on
PortC so no need to configure ANSELC. The port pin assignments default
to the correct values at power on so no need to mess with the PPS registers.
What else needs to be done?
Carey Fisher
-----Original Message-----
Sent: Tuesday, February 27, 2018 3:56 PM
Subject: Re: [PIC] I2C Module on 18F67K40
Carey,
All other functions on those pins must be disabled in your header.
Only the SCL and SDA outputs can be enable. Refer to the spec sheet so
set your registers to disable those functions.
Ray
Post by Carey Fisher
I'm having a terrible time trying to get the I2C module on the
18F67K40 working. My test code is posted below. This code and the I2C
module seem very simple so I must be missing something simple.
This code tries to read address 0000 of an attached 24LC512 EEPROM. I
know the hardware is good because I can use Pic Basic Pro and read
and write the EEPROM using I2C.
The code I'm using came off a forum on the Microchip Support website.
It is "bullet proof". Ha.
I've put debugging statements in the code and what I've found is that
the Interrupt flag, PIR3,SSP1IF, never gets asserted.
Any pointers would be greatly appreciated.
'i2ctest.pbp
'another try at reading I2C data from 24LC512
'Start Condition
'Control Byte for write
'High address byte
'Low address byte
'Start Condition
'Control Byte for read
'Read in data byte
'Return with NACK
'Stop Condition
asm
#define Memtop 0x10000 ;higest memory in the 18F67k40 processor
Startaddress = MemTop-800
SDA = 4
SCL = 3
ORG Startaddress
;***************************************************************
;
; 24LC256 I2C Single Byte Read Routines ;
;
;
_I2CTEST1
rcall I2CInit
;EE_RD
rcall I2CStrt ;send I2C START
movlw h'A6'
rcall I2CSend ;send device address (control byte)
movlw h'00'
rcall I2CSend ;send address hi byte
movlw h'00'
rcall I2CSend ;send address lo byte
rcall I2CStrt ;send I2C START
movlw h'A7'
rcall I2CSend ;send device address (control byte)
EE_R1
rcall I2CRcv ;receive mode (receive byte)
movwf _testbyte1
rcall I2CNack ;signal end of receive
rcall I2CStopp ;send STOP
return ;
;***************************************************************
;
; I2C primitives
;
; SSPADD = ((Fosc/I2Cclock)/4)-1 {formula from AN735} ;
I2CInit
bsf PIE3,SSP1IE ; enable the Interrupt flag, PIR3,SSP1IF
bsf TRISC,SCL ;
bsf TRISC,SDA ;
movlw b'00101000' ;SSPEN + 12C Master
movwf SSP1CON1 ;
movlw b'00000000' ;
movwf SSP1CON2 ;
movlw b'00000000' ;slew rate on for 400khz
movwf SSP1STAT ;
movlw d'13' ;(20000000/100000)-1/4
movwf SSP1ADD ;400khz using 20mhz xtal
return ;
I2CDebug
movf ssp1stat,0
movwf _testbyte1
movf ssp1con1,0
movwf _testbyte2
movf ssp1con2,0
movwf _testbyte3
movf ssp1con3,0
movwf _testbyte4
return
I2CWait
btfss PIR3,SSP1IF ;complete flag?
bra I2CWait ;no, wait
bcf PIR3,SSP1IF ;clear irq flag
return ;
I2CStrt
bsf SSP1CON2,SEN_SSP1CON2 ;send START condition
bra I2CWait ;
I2CStopp
bsf SSP1CON2,PEN ;send STOP condition
bra I2CWait ;
I2CSend
movwf SSP1BUF ;send byte
bra I2CWait ;
I2CRcv
btfsc SSP1STAT,R_W ;transmit complete?
bra I2CRcv ;no, wait
bsf SSP1CON2,RCEN ;receive enable
bcf PIR3,SSP1IF ;clear irq flag
rcall I2CWait ;
movf SSP1BUF,W ;
return ;
I2CAck
bcf SSP1CON2,ACKDT ;set ACK
bra I2CNack+2 ;
I2CNack
bsf SSP1CON2,ACKDT ;set NACK
bsf SSP1CON2,ACKEN ;send ACK or NACK
bra I2CWait ;
I2CRes
bsf SSP1CON2,RSEN ;send RESTART condition
bra I2CWait ;
endasm
Carey Fisher │ Director of Engineering O +1 770-209-0012 x2031 │ F +1
770-209-0719
4295 Hamilton Mill Road │ Suite 100 │ Buford, GA 30518
www.omnimetrix.net
Tell us how we're doing! Click here to take our two-question survey.
     
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mi
Neil
2018-02-28 23:42:09 UTC
Permalink
Are you setting GIE?

Cheers,
-Neil
Post by Carey Fisher
What I meant was, there are no analog peripherals on PORTC so there is no ANSELC register.
The main problem I'm having with using the sample code is the Interrupt flag, PIR3,SSP1IF, never gets asserted. The SCL and SDA lines seem to act correctly when viewed on a scope but the code stops when waiting for the Interrupt flag, PIR3,SSP1IF, to get asserted.
Carey Fisher │ Director of Engineering
P 770-209-0012 ext. 2031
www.omnimetrix.net
-----Original Message-----
Sent: Wednesday, February 28, 2018 2:42 PM
Subject: RE: [PIC] I2C Module on 18F67K40
Carey,
Despite not expecting any analog signals, you still have to disable the analog input to ensure that your I2C lines have the correct impedance. It may seem illogical but that's the way the K series of PICs works.
Best,
Ray
Post by Carey Fisher
Ray,
Thank you for the response.
I've set SSP1CON1.SSPEN to configure the pins. There are no analogs on
PortC so no need to configure ANSELC. The port pin assignments default
to the correct values at power on so no need to mess with the PPS registers.
What else needs to be done?
Carey Fisher
-----Original Message-----
Sent: Tuesday, February 27, 2018 3:56 PM
Subject: Re: [PIC] I2C Module on 18F67K40
Carey,
All other functions on those pins must be disabled in your header.
Only the SCL and SDA outputs can be enable. Refer to the spec sheet so
set your registers to disable those functions.
Ray
Post by Carey Fisher
I'm having a terrible time trying to get the I2C module on the
18F67K40 working. My test code is posted below. This code and the I2C
module seem very simple so I must be missing something simple.
This code tries to read address 0000 of an attached 24LC512 EEPROM. I
know the hardware is good because I can use Pic Basic Pro and read
and write the EEPROM using I2C.
The code I'm using came off a forum on the Microchip Support website.
It is "bullet proof". Ha.
I've put debugging statements in the code and what I've found is that
the Interrupt flag, PIR3,SSP1IF, never gets asserted.
Any pointers would be greatly appreciated.
'i2ctest.pbp
'another try at reading I2C data from 24LC512
'Start Condition
'Control Byte for write
'High address byte
'Low address byte
'Start Condition
'Control Byte for read
'Read in data byte
'Return with NACK
'Stop Condition
asm
#define Memtop 0x10000 ;higest memory in the 18F67k40 processor
Startaddress = MemTop-800
SDA = 4
SCL = 3
ORG Startaddress
;***************************************************************
;
; 24LC256 I2C Single Byte Read Routines ;
;
;
_I2CTEST1
rcall I2CInit
;EE_RD
rcall I2CStrt ;send I2C START
movlw h'A6'
rcall I2CSend ;send device address (control byte)
movlw h'00'
rcall I2CSend ;send address hi byte
movlw h'00'
rcall I2CSend ;send address lo byte
rcall I2CStrt ;send I2C START
movlw h'A7'
rcall I2CSend ;send device address (control byte)
EE_R1
rcall I2CRcv ;receive mode (receive byte)
movwf _testbyte1
rcall I2CNack ;signal end of receive
rcall I2CStopp ;send STOP
return ;
;***************************************************************
;
; I2C primitives
;
; SSPADD = ((Fosc/I2Cclock)/4)-1 {formula from AN735} ;
I2CInit
bsf PIE3,SSP1IE ; enable the Interrupt flag, PIR3,SSP1IF
bsf TRISC,SCL ;
bsf TRISC,SDA ;
movlw b'00101000' ;SSPEN + 12C Master
movwf SSP1CON1 ;
movlw b'00000000' ;
movwf SSP1CON2 ;
movlw b'00000000' ;slew rate on for 400khz
movwf SSP1STAT ;
movlw d'13' ;(20000000/100000)-1/4
movwf SSP1ADD ;400khz using 20mhz xtal
return ;
I2CDebug
movf ssp1stat,0
movwf _testbyte1
movf ssp1con1,0
movwf _testbyte2
movf ssp1con2,0
movwf _testbyte3
movf ssp1con3,0
movwf _testbyte4
return
I2CWait
btfss PIR3,SSP1IF ;complete flag?
bra I2CWait ;no, wait
bcf PIR3,SSP1IF ;clear irq flag
return ;
I2CStrt
bsf SSP1CON2,SEN_SSP1CON2 ;send START condition
bra I2CWait ;
I2CStopp
bsf SSP1CON2,PEN ;send STOP condition
bra I2CWait ;
I2CSend
movwf SSP1BUF ;send byte
bra I2CWait ;
I2CRcv
btfsc SSP1STAT,R_W ;transmit complete?
bra I2CRcv ;no, wait
bsf SSP1CON2,RCEN ;receive enable
bcf PIR3,SSP1IF ;clear irq flag
rcall I2CWait ;
movf SSP1BUF,W ;
return ;
I2CAck
bcf SSP1CON2,ACKDT ;set ACK
bra I2CNack+2 ;
I2CNack
bsf SSP1CON2,ACKDT ;set NACK
bsf SSP1CON2,ACKEN ;send ACK or NACK
bra I2CWait ;
I2CRes
bsf SSP1CON2,RSEN ;send RESTART condition
bra I2CWait ;
endasm
Carey Fisher │ Director of Engineering O +1 770-209-0012 x2031 │ F +1
770-209-0719
4295 Hamilton Mill Road │ Suite 100 │ Buford, GA 30518
www.omnimetrix.net
Tell us how we're doing! Click here to take our two-question survey.
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Loading...