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

18F25K22 and I2C

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



Joined: 10 Dec 2003
Posts: 70
Location: West Sussex, UK

View user's profile Send private message

18F25K22 and I2C
PostPosted: Tue Oct 12, 2010 9:04 am     Reply with quote

Has anyone successfully used the I2C functions on the 18F25K22 ?

I am using compiler v4.112, and my simple test code works when compiled for an 18F252, but not when compiled for the 18F25K22.

I don't even see the start bit generation on the call i2c_start().

And then the call to i2c_write() hangs.

I have tried two different 18F25K22 parts.
_________________
Peter Willis
Development Director
Howard Eaton Lighting Ltd UK
prwatCCS



Joined: 10 Dec 2003
Posts: 70
Location: West Sussex, UK

View user's profile Send private message

PostPosted: Tue Oct 12, 2010 10:47 am     Reply with quote

I am pleased to report that I can now answer my own question!

YES.

The gotcha is as follows : On the 18F25K223 part, many of the port A, B and C inputs default to being ANALOG, not digital. See data sheet p153.

The CCS compiler does NOT take this into consideration, and thus the PORTC input pins for the I2C module are acting as analog in, which seems to prevent the MSSPx module from working.

I added
Code:

#byte ADSELA=0xF38
#byte ADSELB=0xF39
#byte ADSELC=0xF3A

 ADSELA=0x00;
 ADSELB=0x00;
 ADSELC=0x00;

to my hardware initialisation code, and now I see some activity on the I2C SCL/SDA lines. Result.
_________________
Peter Willis
Development Director
Howard Eaton Lighting Ltd UK
languer



Joined: 09 Jan 2004
Posts: 144
Location: USA

View user's profile Send private message

PostPosted: Tue Oct 12, 2010 1:24 pm     Reply with quote

Very good find.

Perhaps it is not well explained in the CCS manual, but in all Microchip datasheets you can find a familiar comment next to the analog inputs: "On a Power-on Reset, Rxx are configured as analog inputs and read as ‘0’.". As far as I know this is true for all the PICs I've used.

CCS lets the user handle this individually. You can use the following command to make all the analog inputs digital: setup_adc_ports(NO_ANALOGS)

In your case, it happened that on the 18F252 the MSSP pins are all digital functions; but on the newer 18F25K223 they are shared with analog functions. And in the analog/digital world, analog trumps digital Smile

Simple case of reading the datasheet and understanding the hardware you are working with.
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