CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

2 x I2C interfaces on PIC 18F27K40

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Momboz



Joined: 03 Jun 2009
Posts: 29

View user's profile Send private message

2 x I2C interfaces on PIC 18F27K40
PostPosted: Fri Jan 20, 2017 1:50 pm     Reply with quote

I would like to use the 2 I2C interfaces on the PIC 18F27K40 at the same time and I have difficulties to make this running.

I have setup the I2C interfaces like this:

Code:
#use i2c(Master,Slow,sda=PIN_B2,scl=PIN_B1,stream=I2C_1)
#use i2c(Master,Slow,sda=PIN_C4,scl=PIN_C3,stream=I2C_2)


But only the interface on C port works properly. The one on B port doesn't react.

Of course I didn't make any changes to the default pins allocations, i.e. no change in the PPS registers.

Any advice or idea?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 20, 2017 2:12 pm     Reply with quote

You have named the streams the opposite of the way they are defined
in the 18F27K40 datasheet. But a stream name is just a name. So that
shouldn't make any difference.

I made a test program with your #use i2c() lines and I noticed both
generated software i2c code in the .LST file. Then I added the following
PPS statements above the #use i2c() lines. Then it generated code for
hardware i2c (for both of them). I didn't test it. But at least it's a step
in the right direction. This is with vs. 5.066.
Code:
#PIN_SELECT SCL1IN   = PIN_C3
#PIN_SELECT SCL1OUT  = PIN_C3
#PIN_SELECT SDA1IN   = PIN_C4
#PIN_SELECT SDA1OUT  = PIN_C4

#PIN_SELECT SCL2IN   = PIN_B1
#PIN_SELECT SCL2OUT  = PIN_B1
#PIN_SELECT SDA2IN   = PIN_B2
#PIN_SELECT SDA2OUT  = PIN_B2


If you need more help, post your compiler version.
Momboz



Joined: 03 Jun 2009
Posts: 29

View user's profile Send private message

PostPosted: Sat Jan 21, 2017 5:29 am     Reply with quote

Yes, You're right I named the streams the opposite way they are defined in the 18F27K40. That was for investigation and, as you said, this has no impact on my program.

I am using compiler version 5.066, the latest.

However some extracts from the .LST file is misleading to me.

Genrated code
#PIN_SELECT SCL1IN = PIN_C3
#PIN_SELECT SCL1OUT = PIN_C3
#PIN_SELECT SDA1IN = PIN_C4
#PIN_SELECT SDA1OUT = PIN_C4
#use i2c(Master,Slow,sda=PIN_C4,scl=PIN_C3,stream=I2C_1)
Code:
00370:  BCF    F96.7
00372:  MOVLB  E
00374:  BCF    xCD.0
00376:  MOVFF  2B,F92
0037A:  MOVLW  02
0037C:  BTFSC  F96.7
0037E:  BRA    038A
00380:  BTFSS  xCD.0
00382:  BRA    0380
00384:  MOVLW  00
00386:  BTFSC  F97.6
00388:  MOVLW  01
0038A:  MOVWF  01
0038C:  MOVLB  0
0038E:  RETURN 0
00390:  BCF    F96.6
00392:  BSF    F97.3
00394:  BTFSC  F97.3
00396:  BRA    0394
00398:  BTFSC  00.0
0039A:  BCF    F97.5
0039C:  BTFSS  00.0
0039E:  BSF    F97.5
003A0:  BSF    F97.4
003A2:  BTFSC  F97.4
003A4:  BRA    03A2
003A6:  MOVFF  F92,01
003AA:  GOTO   03DC

and generated code for
#PIN_SELECT SCL2IN = PIN_B1
#PIN_SELECT SCL2OUT = PIN_B1
#PIN_SELECT SDA2IN = PIN_B2
#PIN_SELECT SDA2OUT = PIN_B2
#use i2c(Master,Slow,sda=PIN_B2,scl=PIN_B1,stream=I2C_1)
Code:
00370:  MOVLB  E
00372:  BCF    x96.7
00374:  BCF    xCD.2
00376:  MOVFF  2B,E92
0037A:  MOVLW  02
0037C:  BTFSC  x96.7
0037E:  BRA    038A
00380:  BTFSS  xCD.2
00382:  BRA    0380
00384:  MOVLW  00
00386:  BTFSC  x97.6
00388:  MOVLW  01
0038A:  MOVWF  01
0038C:  MOVLB  0
0038E:  RETURN 0
00390:  MOVLB  E
00392:  BCF    x96.6
00394:  BSF    x97.3
00396:  BTFSC  x97.3
00398:  BRA    0396
0039A:  BTFSC  00.0
0039C:  BCF    x97.5
0039E:  BTFSS  00.0
003A0:  BSF    x97.5
003A2:  BSF    x97.4
003A4:  BTFSC  x97.4
003A6:  BRA    03A4
003A8:  MOVFF  E92,01
003AC:  MOVLB  0
003AE:  GOTO   03E8

i2c for C port and B port have configuration registers F96h and E96h and the generated codes seem (at least to me) not to be consistent.
The first one works fine, the other doesn't.

Any view on that?

PS: I am using the same stream name I2C_1 for both configuration just to avoid my program at each change.
Ttelmah



Joined: 11 Mar 2010
Posts: 19549

View user's profile Send private message

PostPosted: Sat Jan 21, 2017 10:32 am     Reply with quote

Both lots of code are functionally identical. The first talks to 0xF96, and the second to 0xE96.
You can directly address a register as 0xF96, or can set the bank to F, and talk to x96. It's switching between these two ways of working. Shouldn't make any difference, and probably reflects that the PIR register (which both have to talk to - bit 0, and bit 2 of 0xECD), is in bank E, so there is a difference in the bank switching needed.

Also you do realise that the interrupt number involved would change as well, if you use this?.
Momboz



Joined: 03 Jun 2009
Posts: 29

View user's profile Send private message

PostPosted: Tue Jan 24, 2017 6:17 am     Reply with quote

I haven't been using interrupt routines.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group