|
|
View previous topic :: View next topic |
Author |
Message |
Arizona Chris
Joined: 20 Dec 2014 Posts: 69 Location: Arizona
|
Question on Tris setting when using SDA and SCL hardware.... |
Posted: Sun Jun 14, 2015 6:58 pm |
|
|
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
|
|
Posted: Sun Jun 14, 2015 7:59 pm |
|
|
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
|
i2cpins |
Posted: Sun Jun 14, 2015 8:28 pm |
|
|
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 |
|
|
|
|
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
|