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

Question on Tris setting when using SDA and SCL hardware....

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



Joined: 20 Dec 2014
Posts: 69
Location: Arizona

View user's profile Send private message Visit poster's website

Question on Tris setting when using SDA and SCL hardware....
PostPosted: Sun Jun 14, 2015 6:58 pm     Reply with quote

Hello all,

hopefully not too silly of a question. I'm writing interface drivers for an i2c digital device, and as of right now, I'm using "fast_io" and set the tris settings for each port in the main program. But when using the 877a hardware I2C ports (C3, C4) I can see you would use "output" for SCL, but since SCA is bidirectional, what to do?

The test program for the driver runs fine if I omit the fast io, and let CCS set the ports. is there a general rule here? I want to import my mini test program (no tris defined) into the main program which has fast_io and all tris defined. I guess I could leave the tris C out for now?

#use I2C(master, sda=PIN_C4, scl=PIN_C3, slow)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 14, 2015 7:59 pm     Reply with quote

Arizona Chris wrote:

I can see you would use "output" for SCL, but since SCA is bidirectional,
what to do?

No, the 16F877A data sheet says both pins must be set as inputs:
Quote:

9.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.

Data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/39582C.pdf

Arizona Chris wrote:

But when using the 877a hardware I2C ports (C3, C4)
#use I2C(master, sda=PIN_C4, scl=PIN_C3, slow)

The #use i2c() line above will use software i2c. To make the compiler
use hardware i2c, you have to add FORCE_HW to that line (and use
the hardware i2c pins).

Arizona Chris wrote:

I want to import my mini test program (no tris defined) into the main
program which has fast_io and all tris defined. I guess I could leave the
tris C out for now?

You can still use fast i/o with a set_tris_c() statement. Just make sure you
set pins C3 and C4 to be inputs in that statement.
Arizona Chris



Joined: 20 Dec 2014
Posts: 69
Location: Arizona

View user's profile Send private message Visit poster's website

i2cpins
PostPosted: Sun Jun 14, 2015 8:28 pm     Reply with quote

THANK YOU PCM, I am having so much fun getting the code up and running on my digital compass, Im using the Adafruit HMC5883 break out board, and its totally awesome - has all the 3.3 to 5v conversion, and get this - is 9 bucks each! got it working in short order, now making the program optimized.

Chris
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