View previous topic :: View next topic |
Author |
Message |
splater Guest
|
i2c with PIC12F675 |
Posted: Mon Jun 12, 2006 4:07 am |
|
|
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
|
|
|
![](templates/subSilver/images/spacer.gif) |
VanHauser
Joined: 03 Oct 2005 Posts: 88 Location: Ploiesti, Romania
|
|
Posted: Mon Jun 12, 2006 4:49 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Mon Jun 12, 2006 8:37 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jun 12, 2006 11:53 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Mon Jun 12, 2006 12:39 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
elellilrah
Joined: 29 Aug 2007 Posts: 14
|
Needs #use i2c in header file |
Posted: Tue Dec 11, 2007 11:34 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
|