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.h not found?

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



Joined: 13 Feb 2012
Posts: 21

View user's profile Send private message

i2c.h not found?
PostPosted: Thu Feb 16, 2012 12:16 pm     Reply with quote

Hi,

I'm using a PIC 16F887 to run an I2C bus. I chose this for a variety of reasons and that it included i2c lines.

However, when I try and program it, the header file isn't found. What gives?

Talking to colleagues it seems that the best method to solve this is actually to upgrade to a PIC18F family and use an alternate compiler.

I've looked in the install folder and i2c.h is not there. Does anyone have a link to one that is compatible with CCS, as the ones I've found have failed to compile.
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Feb 16, 2012 1:46 pm     Reply with quote

You should always give the compiler type and version when posting.
There is no 'I2C.H' file that I'm aware as 'drivers' are specific to the devices that they are to be used with. IE. to access say an I2C RTC chip you need a driver that was coded for it and not, say, an I2C EEPROM.
CCS C compiler is very powerful, they supply drivers for a lot of devices, located in the drivers folder and any 2 pins can be used for an I2C bus.
Tell us the device you want to use,odds are there might already be a driver for it. If not, they are easy to cut.
FreakShow!



Joined: 13 Feb 2012
Posts: 21

View user's profile Send private message

PostPosted: Thu Feb 16, 2012 2:03 pm     Reply with quote

Hi,

Device I'm using is a PIC16F887.

Using MPLAB 8.3 and CCS Compiler version 4.120.

If I need to use an alternative chip, is there a good method of selecting the options I want in the chip to whittle the choice down?

I need quite a few things like I2C, PWM and a total I/O of about 30.

EDIT: See, I have C code that is very easy to use with the header file. But without it, I have no idea how to send the signals I want.

This line:

Code:
#use i2c(Slave, I2C1, address=0x22, force_hw, stream=slave)


Compiles just fine though. So it must be aware of i2c somewhere. But I see no trace of it in the header file for the device.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 16, 2012 2:22 pm     Reply with quote

To use the built-in i2c functions, you must place a #use i2c() statement
in your program. Refer to the CCS manual for the allowable parameters
for #use i2c():
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
Once you put the #use i2c() statement in your program, then you can call
the built-in i2c functions.

Refer to CCS example driver files for i2c eeproms, to see how to build
device driver functions using the built-in i2c functions. Example:
Quote:

c:\program files\picc\drivers\24256.c


If you want to make your PIC be an i2c slave, then search on: i2c slave
in the forum's search page. Set it for: Search for All Terms

Use the forum's search page to search for answers on any problems you
may have. Most answers are already in the forum archives.
FreakShow!



Joined: 13 Feb 2012
Posts: 21

View user's profile Send private message

PostPosted: Thu Feb 16, 2012 2:52 pm     Reply with quote

Apologies, this does seem a stupid post. After making the thread I did find the manual and all the functions.

I'd just gotten hung up on the lack of header file and assumed it wouldn't.

I have one remaining question though.

I'm using this to read data off the Wii Ir camera and to initialise I need:

Code:
Just write the following byte sequences, with a small delay between writes (assumes a successful ACK). The first byte on each line is the register you are writing to.
0×30 0×01
0×30 0×08
0×06 0×90
0×08 0xC0
0x1A 0×40
0×33 0×33


so as I want to send 7-bit address, 0x30 is decimal 48. And to get that in 7-bits, I'd want B 0110000
And to write is a 0. Therefore i need to transmit:

B 01100001

or 0x61

So therefore to do the first line it's:

Code:
i2c_start();
i2c_write(0x61);
i2c_write(0x01);
i2c_stop();
delay_ms(5); //I believe I read somewhere that 5ms was needed between for the pauses between each.


Is that right, or have I complicated it all up, or does it automatically sort out the bits and I just need to pass the bytes?

Thanks in advance.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 16, 2012 2:59 pm     Reply with quote

A register address within a Slave device is not the same thing as the
Slave's i2c address.

The slave device will have a "slave address". Look in the documentation
for the Wii device to find out what it is. If it's given in Philip's 7-bit format,
you will need to left-shift it by 1 bit to put it in CCS's 8-bit format.
Register addresses should not be left-shifted. Use them "as is".

I would advise that you read this thread on interfacing the Wii Nunchuck.
It goes through some of the problems that you're going to have, and it
has the answers. This is a 2-page thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=32753
Also this one:
http://www.ccsinfo.com/forum/viewtopic.php?t=45002
FreakShow!



Joined: 13 Feb 2012
Posts: 21

View user's profile Send private message

PostPosted: Thu Feb 16, 2012 3:01 pm     Reply with quote

Thank you for all your help. I will read carefully.
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