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

2 software i2c and hardware spi

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



Joined: 28 Jul 2004
Posts: 32

View user's profile Send private message

2 software i2c and hardware spi
PostPosted: Wed Aug 25, 2004 4:46 am     Reply with quote

is it possible to implement 2 software i2c and 1 hardward spi in a 16f876?
Charlie U



Joined: 09 Sep 2003
Posts: 183
Location: Somewhere under water in the Great Lakes

View user's profile Send private message

PostPosted: Wed Aug 25, 2004 6:17 am     Reply with quote

Yes, I have done it, and it worked quite well.
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

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

PostPosted: Wed Aug 25, 2004 7:56 am     Reply with quote

Charlie, Can you share the code? Put a copy in the code library.
http://www.ccsinfo.com/forum/viewforum.php?f=2
Charlie U



Joined: 09 Sep 2003
Posts: 183
Location: Somewhere under water in the Great Lakes

View user's profile Send private message

PostPosted: Wed Aug 25, 2004 4:41 pm     Reply with quote

Sorry, but I can't post the actual code because it belongs to one of my clients. However, it isn't that tough to recreate. The major hurdle (which isn't very high ;-) ) is how to organize access through the various interfaces.

I'll walk through the concept and let you ask questions later if this doesn't end up being very clear.

Let's say you are controlling a digital pot with the hardware spi interface, and you want to communicate with a real time clock via I2C and a memory chip via I2C. Unfortunately, the rtc and memory have the same i2c address. You now need to use 2 separate i2c interfaces. One great feature of the CCS compiler is that hardware and software I2C interfaces are handled the same. The compiler takes care of all of the house keeping.

First, set up the spi as you would for any other application. There are plenty of examples on this forum and in the example files. I would then create an include file that contains all of the functions that you need to control the digital pot. Call this file dig_pot.c for example.

Next, create a file for functions that access the rtc for setting and reading the time, etc. Call this file rtc_io.c for example. At the beginning of this file include the directive:

#use I2C (master, sda=RTC_SDA, scl=RTC_SCL, FAST)

where RTC_SDA and RTC_SCL are previously defined pins that you are using for the rtc i2c interface. Include in this file your set of functions for accessing the rtc such as rtc_set_minutes(); rtc_set_hours(); rtc_read_minutes(); etc. These functions will include the standard CCS I2C access calls.

Next, create a file for functions that read and write the memory. Call this file mem_io.c for example. At the beginning of this file include the directive:

#use I2C (master, sda=MEM_SDA, scl=MEM_SCL, FAST)

where MEM_SDA and MEM_SCL are previously defined pins that you are using for the memory i2c interface. Again, include in this file your set of functions for reading and writing memory such as read_ext_mem(); or write_ext_mem(). As above, these functions will include the standard CCS I2C access calls.

The compiler will automatically use the correct pins for each function, based on the previous #use directive. As I recall, you should use standard io for the ports that include the soft i2c interfaces, since the data pin of an i2c interface changes from an output to an input and back during a single i2c call.

Let us know if this is helpful.

Charlie
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

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

PostPosted: Thu Aug 26, 2004 9:54 am     Reply with quote

Any considerations for the soft port. Is open collector OK? or will most any pin do OK?
Charlie U



Joined: 09 Sep 2003
Posts: 183
Location: Somewhere under water in the Great Lakes

View user's profile Send private message

PostPosted: Thu Aug 26, 2004 10:23 am     Reply with quote

Any port should work fine, open collector or not. When a pin is idle, the compiler will make it an input so it does not load the bus. Don't forget the standard i2c pullups on each bus, both clock and data, somewhere between 2.2k and 4.7k. Other values may work, but this is the common range.
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

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

PostPosted: Fri Aug 27, 2004 8:03 am     Reply with quote

Thanks
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