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 CCS Technical Support

I2C general questions - help

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



Joined: 17 Jan 2006
Posts: 66

View user's profile Send private message

I2C general questions - help
PostPosted: Tue Oct 17, 2006 3:50 am     Reply with quote

Hello All,
I'm working in a quite big project in which I need to use two I2C devices: one is a M24512 external memory from ST and another one is a set of several PCF8574 8bit I/O expander from Philips.
I have found the 24512.C driver for the memory and jds's for the expander.
I still dont have a prototype PCB in order to develop and debug so, I have tried using a simulator: Proteus ISIS 6.5. The problem is that the models are absent or dont work properly. Well, I preffer to think they don't work properly...
That means I can't try wether the drivers are OK or not. Anyway, this is the first time I use I2C, and although I2C seems to be very simple I'd like to ask you several questions in order to clarify some points. Here we go:

1) For using I2C in my code, is it enough with including #use i2c(...)?
2) Do all devices need a "i2c_init()" function or only memories?
3) Could someone who has already used I2C with succes tell me some general directives I should follow?


Once again... THANK YOU VERY MUCH Very Happy

Juanma
Neckruin



Joined: 17 Jan 2006
Posts: 66

View user's profile Send private message

PostPosted: Tue Oct 17, 2006 8:04 am     Reply with quote

Oooohhhh Sad
No answers yet
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 17, 2006 12:56 pm     Reply with quote

Quote:
1) For using I2C in my code, is it enough with including #use i2c(...)?

That line will add the CCS i2c library code to your project, and also
configure it for your selected pins, and mode settings.
You will also need to #include a driver file for your i2c device.
The driver file will call the low level functions in the i2c library code.
Example of driver file: 24256.C for a 24LC256 eeprom

Quote:

2) Do all devices need a "i2c_init()" function or only memories?

In the eeprom files, the i2c_init() function sets the i2c pins as inputs.
The PIC i/o pins are typically set as inputs automatically upon
power-on reset (in hardware), so I'm not sure why CCS has
included the init function in the driver. Normally, pins that are
used for i2c are not used for any other purpose in a design.
So, when would they ever have been set to be output pins ?
I don't know. Probably never.

Quote:

3) Could someone who has already used I2C with succes tell me some
general directives I should follow ?

Make sure you have the pull-up resistors. Somewhere between 2.2K
and 4.7K is a normal value.
Neckruin



Joined: 17 Jan 2006
Posts: 66

View user's profile Send private message

PostPosted: Wed Oct 18, 2006 1:08 am     Reply with quote

Thank you very much PCM.
I'd like to take advance of this chance to ask you another question. In case this is not the correct place I don't mind posting it in the general forum, anyway here it is my question:

I'm using the MPLAB plugin from CCS to use the CCS compiler within MPLAB: How can I add code files (like drivers) to my project? I tried with #include <XXX> but it didn't work. Which is the correct way to do that in MPLAB?

Thanks,

Juanma
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 18, 2006 1:25 am     Reply with quote

Quote:

How can I add code files (like drivers) to my project? I tried with
#include <XXX> but it didn't work. Which is the correct way to do
that in MPLAB ?

You still have to use #include statements to include all your
drivers and modules in your main source file. (There's no
linker). I assume your question is about how to add other
files to the MPLAB project window, besides your main source file.

Here's the answer:

See this MPLAB screen-shot from the CCS tutorial:
http://www.ccsinfo.com/images/faq/mplab/mplab-wiz8.gif
In the Project window, right-click on "Other Files". Then add
your driver files and other modules there. Then you can
easily access them, instead of having to click on "Open"
or "Recent Files" every time you want to edit a module file.
Neckruin



Joined: 17 Jan 2006
Posts: 66

View user's profile Send private message

PostPosted: Wed Oct 18, 2006 1:46 am     Reply with quote

FROM CCS MPLAB IDE FAQ:
Quote:
Do not add more than one .C file under Source Files in the Project Window. If you add more than one .C file here when you compile your project MPLAB will compile each .C file individually and then attempt to link them. Since CCS does not include a linker this will always give you an error.


So, this means that I can have only ONE source code file in my project? This means I can't divide the code in several files but should copy and paste the drivers in a single file, isn't it?
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Wed Oct 18, 2006 1:54 am     Reply with quote

Neckruin wrote:
FROM CCS MPLAB IDE FAQ:
Quote:
Do not add more than one .C file under Source Files in the Project Window. If you add more than one .C file here when you compile your project MPLAB will compile each .C file individually and then attempt to link them. Since CCS does not include a linker this will always give you an error.


So, this means that I can have only ONE source code file in my project? This means I can't divide the code in several files but should copy and paste the drivers in a single file, isn't it?


You can still divide your code into several files and then use #include instead of copy/paste.
Code:

#include "mysourcefile.c"
#include "myheaderfile.h"  // the header might have executable code, not just declarations


Last edited by kender on Wed Oct 18, 2006 2:01 am; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 18, 2006 1:57 am     Reply with quote

Here's another example:
http://www.ccsinfo.com/forum/viewtopic.php?t=18649&start=1
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