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

Using I2C hardware - a quick reminder

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



Joined: 15 Sep 2003
Posts: 184
Location: Warrington UK

View user's profile Send private message

Using I2C hardware - a quick reminder
PostPosted: Thu Jan 29, 2009 9:05 am     Reply with quote

Just a note , if you find that when you are using I2C,
that the force_sw works ( thus forcing the compiler to use software bit banging).
BUT even with I2C hardware present, the force_hw just wont burst into life.

to use h/ware I2C, you MUST set the SDA and SCL tris bits to 1 to set them as inputs. using SET_TRIS_C( 0x18 ); for C3 and C4 as appropriate

Its only when you dig into the datasheet that this becomes plain and clear.
dyeatman



Joined: 06 Sep 2003
Posts: 1931
Location: Norman, OK

View user's profile Send private message

PostPosted: Thu Jan 29, 2009 12:19 pm     Reply with quote

That may be true in the data sheet but I would disagree that a CCS user has to do anything out of the ordinary. No TRIS statements should be required at all unless you are overriding the compiler using FAST_IO(). I use I2C all the time, letting the compiler handle the TRIS, and I have never had any problems with either HW or SW I2C. I specify the correct pins and never use force_hw.

What compiler are you using? I am using version 4.81 of PCM and PCH with the 16F877, 16F887, 18F4520 and 18F4550, no problems at all.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 29, 2009 1:24 pm     Reply with quote

The 18F452 data sheet says the SDA and SCL pins must be set to inputs
by the user:
Quote:

15.4.2 OPERATION
Selection of any I2C mode, with the SSPEN bit set,
forces the SCL and SDA pins to be open drain, provided
these pins are programmed to inputs by setting
the appropriate TRISC bits.

CCS does this for you. Here's the start-up code inserted by the
compiler. You can see that it sets pins C3 and C4 to inputs:
Quote:

.................... void main()
.................... {
0022: CLRF TBLPTRU
0024: BCF RCON.IPEN
0026: CLRF FSR0H
0028: CLRF FSR0L
002A: BSF TRISC.3
002C: BSF TRISC.4
002E: MOVLW 09
0030: MOVWF SSPADD
0032: MOVLW 28
0034: MOVWF SSPCON1
0036: BSF SSPSTAT.SMP
0038: BCF SSPSTAT.CKE
003A: BSF ADCON1.PCFG0
003C: BSF ADCON1.PCFG1
003E: BSF ADCON1.PCFG2
0040: BCF ADCON1.PCFG3

Here's the test program:
Code:
#include <18F452.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use i2c(Master, sda=PIN_C4, scl=PIN_C3, FORCE_HW)
//===============================
void main()
{
i2c_write(0x55);

while(1);
}
dyeatman



Joined: 06 Sep 2003
Posts: 1931
Location: Norman, OK

View user's profile Send private message

PostPosted: Thu Jan 29, 2009 1:57 pm     Reply with quote

PCM,
You are really good at picking up on someone who posted earlier and
remembering what PIC they are using. I don't have a clue where you saw
he had an 18F452.... Smile
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