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 support@ccsinfo.com

I2C problems with PIC18F47K42

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



Joined: 26 Feb 2018
Posts: 5

View user's profile Send private message

I2C problems with PIC18F47K42
PostPosted: Mon Feb 26, 2018 4:25 am     Reply with quote

Hello

I am having trouble with using the I2C HW of a pic18F47K42. If i use FORCE_SW, everything works. I am using following to configure the I2C:

Code:

//Select I2C with PPS

#PIN_SELECT SCL1IN = PIN_C3
#PIN_SELECT SCL1OUT = PIN_C3
#PIN_SELECT SDA1IN = PIN_C4
#PIN_SELECT SDA1OUT = PIN_C4

#use i2c(Master,Slow,I2C1,FORCE_HW)


I tried I2C with the XC8 compiler and the MCC (microchip code generator). This works, so i am sure that my chip is working OK.

Somebody that knows what i am doing wrong?

I tried to do following, but with no success:
- Set pins as open drain.
- Set them as input or as output
- Using I2C1 or define pins again in #use i2c

Thanks in advance.
Ttelmah



Joined: 11 Mar 2010
Posts: 13054

View user's profile Send private message

PostPosted: Mon Feb 26, 2018 6:25 am     Reply with quote

I would use this:
Code:

//Select I2C with PPS
#PIN_SELECT SCL1 = PIN_C3
#PIN_SELECT SDA1 = PIN_C4

//Using the peripheral name always forces hardware
#use i2c(Master,Slow=100000,I2C1)


You only need to map separate in/out functions, where these are separate paths on the same peripheral. I don't think these are separate on this peripheral, and the SCL in, is for the slave device only.
BartDelboo



Joined: 26 Feb 2018
Posts: 5

View user's profile Send private message

PostPosted: Mon Feb 26, 2018 7:40 am     Reply with quote

Ok, i tried the code you suggested, but still no activity at all on the I2C bus.
If i look with my scope, i see that SDA and SCL lines remain high.
Some other ideas? Someone already tested I2C with this type of PIC (18F47K42)?

I find it strange that FORCE_SW and XC8 compiler work. Can it be that there is a fault in the compiler or the PIC header file?

Thanks!
temtronic



Joined: 01 Jul 2010
Posts: 6066
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Feb 26, 2018 7:51 am     Reply with quote

Simple to see, just dump both the listings of the compiled code, and compare.
Ttelmah



Joined: 11 Mar 2010
Posts: 13054

View user's profile Send private message

PostPosted: Mon Feb 26, 2018 9:16 am     Reply with quote

I suggest you ask CCS. This is very much a beta chip at present. The current compiler is the first listing it.....
It's only just been added to the devices supported list.
MicroChip always have the advantage of writing the compiler before the chips are released. CCS have to wait till they are given data to start.
Talk to them nicely, and they will probably give you an example.
They do show SDA in and out as two separate mappings, so I'd actually expect it to need:
Code:

//Select I2C with PPS
#PIN_SELECT SCL1 = PIN_C3
#PIN_SELECT SDA1IN = PIN_C4
#PIN_SELECT SDA1IOUT = PIN_C4

//Using the peripheral name always forces hardware
#use i2c(Master,Slow=100000,I2C1)

I'd also be explicitly ensuring the analog is off on those pins, and that the timer2 input is disabled.
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