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 with PIC12F675

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







i2c with PIC12F675
PostPosted: Mon Jun 12, 2006 4:07 am     Reply with quote

Hi everyone,

someone can tell me wether it's possible to use I2C with this PIC? Is there a way to emule the I2C ?

I have this driver: (working for the 18F4620

Code:

#ifndef EEPROM_SDA


#define EEPROM_WRITE_ADDRESS 0xA2l
#define EEPROM_READ_ADDRESS  0xA3

#endif

#define hi(x)  (*(&x+1))

#use i2c(master,sda=EEPROM_SDA, scl=EEPROM_SCL)

#define EEPROM_ADDRESS long int
#define EEPROM_SIZE    8192

void init_ext_eeprom() {
   output_low(eeprom_scl);
   output_high(eeprom_sda);
}


void write_ext_eeprom(long int address, byte data) {

   i2c_start();
   i2c_write(EEPROM_WRITE_ADDRESS);
   i2c_write(hi(address));
   i2c_write(address);
   i2c_write(data);
   i2c_stop();
   delay_ms(11);
}


byte read_ext_eeprom(long int address) {
   byte data;

   i2c_start();
   i2c_write(EEPROM_WRITE_ADDRESS);
   i2c_write(hi(address));
   i2c_write(address);
   i2c_start();
   i2c_write(EEPROM_READ_ADDRESS);
   data=i2c_read(0);
   i2c_stop();
   return(data);
}

but I have these errors ...

Quote:

Undefined identifier i2c_stop
Undefined identifier i2c_start
Undefined identifier i2c_write
VanHauser



Joined: 03 Oct 2005
Posts: 88
Location: Ploiesti, Romania

View user's profile Send private message

PostPosted: Mon Jun 12, 2006 4:49 am     Reply with quote

Did you define the EEPROM_SCL and EEPROM_SDA pins before this driver?

What version of the compiler are you using? I don't know since what version, but in recent ones I2C is emulated automatically if there is no hardware support or the SCL and SDA defined pins don't match the hardware I2C pins.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Mon Jun 12, 2006 8:37 am     Reply with quote

I just tried making a small test program using this PIC using version 3.249. The wizard doesn't support I2C for this one but I manually entered

#use i2c(master,SDA=PIN_A0,SCL=PIN_A1)

into the .h file and then entered:

i2c_start();
i2c_write(0x80);
var = i2c_read();
i2c_stop();

into main() and it compiled properly.

Try making something that is extremely basic, nothing fancy, that includes those things and see if it compiles.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 12, 2006 11:53 am     Reply with quote

Quote:
but in recent ones I2C is emulated automatically if there is no hardware
support or the SCL and SDA defined pins don't match the hardware I2C pins.

They have done this for at least 8 years, and probably longer.
treitmey



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

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

PostPosted: Mon Jun 12, 2006 12:39 pm     Reply with quote

Yup, right from the help file for #USE I2C
Quote:
Software functions are generated unless the FORCE_HW is specified.

What I mean to say is that you always get a "bit banged" I2C unless you say "FORCE_HW" and that can be used on any PIC and any pins.
well, perhaps not port A open collector, or someother weird pins
elellilrah



Joined: 29 Aug 2007
Posts: 14

View user's profile Send private message

Needs #use i2c in header file
PostPosted: Tue Dec 11, 2007 11:34 pm     Reply with quote

I was having the same trouble when I ran into your posting. I'm using CCS version 3.241 which requires additional files to be header files, as this compiler version can't handle multiple C files.

I keep all my functions in .h files which are included in the top of my main.c file. When creating a project to use the I2C, I kept getting the same error:

Undefined identifier -- i2c_stop()

Once I added the following line to the top of any header file that I'm using the i2c routines with,

#use i2c(Master,Slow,sda=PIN_C4,scl=PIN_C3,force_hw)

as well as placing this line at the top of my main.c file, the error went away.
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