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

PIC16F886 I2C

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



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PIC16F886 I2C
PostPosted: Thu Mar 18, 2010 4:05 pm     Reply with quote

Hi!

I am using a 16f886 to control a philips TEA5767 FM radio chip by I2C.

The initial test was done with a pic16f877 with hardware I2C:

Code:

#include <16F877A.h>
#fuses    HS,NOWDT,NOPROTECT,NOLVP
#use    delay(clock=20M)

#define Device_SCL PIN_C3 
#define Device_SDA PIN_C4 
 
#use i2c(master, sda=Device_SDA, scl=Device_SCL,FORCE_HW) 



This worked fine but when I changed to the 16f886 with the same fuses for I2C it stopped working.

After much searching I found that I can make it work only in software I2C and by defining SLOW speed:

Code:

#include <16F886.h>

#fuses    XT,NOWDT,NOPROTECT,NOLVP,MCLR
#use       delay(clock=4M)

#define Device_SCL PIN_C3 
#define Device_SDA PIN_C4 
 
#use i2c(master, sda=Device_SDA, scl=Device_SCL,SLOW) 


I cannot make it work with hardware I2C. Is there something special about the 886 chip?? I am using the internal 4MHz oscillator if that matters.

In both cases I have pullup resistors for the I2C pins and defined these pins as outputs.

Thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 18, 2010 4:25 pm     Reply with quote

Quote:

In both cases I have pullup resistors for the I2C pins and defined these
pins as outputs.

The 16F886 manual says the pins must be defined as inputs.
The CCS #use i2c() library code should do this for you, automatically.
You should not define them as output pins with code.
Quote:

13.4 MSSP I2C Operation

The user must configure these pins as inputs or outputs
through the TRISC<4:3> bits.


If you still have problems, then post your compiler version.
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Thu Mar 18, 2010 4:49 pm     Reply with quote

Thanks for the reply!

The manual says "The user must configure these pins as inputs or outputs"
this means inputs or outputs? Confused It worked with the 877 with outputs defined.

Anyway, I changed these to inputs and it worked with hardware I2C and without the "slow" definition.
PCM programmer You are right as always!

Maybe the CCS code did not do this automatically because I use fast_io.

But how did you understand that it must be inputs?
Please explain to me.

Thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 18, 2010 5:27 pm     Reply with quote

OK, sorry.

That text in the data sheet is incorrect. I copied and pasted it in without
reading it closely.

Here is the traditional text from the 16F877 data sheet. Notice
that it says "inputs" only.
Quote:

Before selecting any I2C mode, the SCL and SDA pins must be
programmed to inputs by setting the appropriate TRIS bits.

But unfortunately, in some of the newer PICs, the incorrect statement
of "inputs or outputs" was placed into the data sheets. I emailed
Microchip Tech Support about this, maybe a few years ago. A tech
support person agreed that it should say "The user must configure
these pins as inputs". He said he would get it changed in the data
sheets, but maybe it didn't happen.
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Thu Mar 18, 2010 5:35 pm     Reply with quote

I see!
But keep in mind that with the 877 it worked with the pins defined as outputs and without pull-up resistors. Great chip ;)

Anyway, problem solved! Smile

Thank you so much for your time.
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