View previous topic :: View next topic |
Author |
Message |
Neckruin
Joined: 17 Jan 2006 Posts: 66
|
I2C general questions - help |
Posted: Tue Oct 17, 2006 3:50 am |
|
|
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
Juanma |
|
|
Neckruin
Joined: 17 Jan 2006 Posts: 66
|
|
Posted: Tue Oct 17, 2006 8:04 am |
|
|
Oooohhhh
No answers yet |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Oct 17, 2006 12:56 pm |
|
|
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
|
|
Posted: Wed Oct 18, 2006 1:08 am |
|
|
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
|
|
Posted: Wed Oct 18, 2006 1:25 am |
|
|
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
|
|
Posted: Wed Oct 18, 2006 1:46 am |
|
|
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
|
|
Posted: Wed Oct 18, 2006 1:54 am |
|
|
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
|
|
|
|