View previous topic :: View next topic |
Author |
Message |
georpo
Joined: 18 Nov 2008 Posts: 281 Location: Athens, Greece.
|
PIC16F886 I2C |
Posted: Thu Mar 18, 2010 4:05 pm |
|
|
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
|
|
Posted: Thu Mar 18, 2010 4:25 pm |
|
|
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.
|
|
Posted: Thu Mar 18, 2010 4:49 pm |
|
|
Thanks for the reply!
The manual says "The user must configure these pins as inputs or outputs"
this means inputs or outputs? 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
|
|
Posted: Thu Mar 18, 2010 5:27 pm |
|
|
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.
|
|
Posted: Thu Mar 18, 2010 5:35 pm |
|
|
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!
Thank you so much for your time. |
|
|
|