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

reusing #use (spi and i2c) - help!

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



Joined: 02 Apr 2012
Posts: 22

View user's profile Send private message

reusing #use (spi and i2c) - help!
PostPosted: Fri Aug 29, 2014 11:22 am     Reply with quote

Hi all,
I've got a tricky problem. My hardware is constrained by lack of pins, so I combined i2c and spi peripheral devices, sharing clock and data lines (using the software driver libraries).

Electrically it works fine and I am able to configure the i2c devices first, then the #use SPI call, then the SPI device is accessed. All OK.

However, now I need my program to access one of the i2c devices occasionally, after the #spi call.

But apparently the #use i2c call can't be done more than once. I get
Code:
Option invalid   Bad Option: 116



How can I get the libraries to share? I realise this is a little non-standard but I know the library code is there and it does work perfectly.

Is the only way to code my own SPI routine? That would be a pain!

Thanks
Evan
Ttelmah



Joined: 11 Mar 2010
Posts: 19448

View user's profile Send private message

PostPosted: Fri Aug 29, 2014 1:14 pm     Reply with quote

Key to understand, is that #use, is a preprocessor directive, not code.

Setup the two #use statements, with different stream names, and use these with the i2c/spi functions.

However I'm very surprised you can mix the buses. Given that I2C, is an 'open collector' bus, while SPI requires hardware pull up/down.

Tell the two statements to both force software mode, and then manually float/drive the pins involved, before switching.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 29, 2014 7:13 pm     Reply with quote

This thread has many links on i2c and spi on the same pins:
http://www.ccsinfo.com/forum/viewtopic.php?t=41578
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