View previous topic :: View next topic |
Author |
Message |
h.a.j.molenaar
Joined: 04 May 2005 Posts: 9
|
Strange behaviour I2C with 16F876 |
Posted: Thu Aug 09, 2007 5:02 am |
|
|
Hi all,
Encountering a strange behaviour using I2C with a 16F876 (has hardware I2C).
When I use:
#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3) so with software bit-banging everything works fine.
On the other hand when I use:
#use i2c(Master,FORCE_HW,FAST = 3686400, sda=PIN_C4,scl=PIN_C3)
so using the hardware I2C, the micro is clocked with 3.6864 Mhz then
the SCL pin is pulled to ground and the program hangs. SDA remains high.
Both pins have a pull-up to Vdd.
Have anyone experience with this, regards Hugo. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Aug 09, 2007 5:38 am |
|
|
Code: | #use i2c(Master,FORCE_HW,FAST = 3686400, sda=PIN_C4,scl=PIN_C3) | You want to clock the I2C with 3.68MHz? Isn't that a bit fast?
The fastest clock you can select for I2C is Fosc / 4. According to Table 15-9 of the datasheet you have to clock the PIC at a minimum of 1.5MHz to meet the 100kHz mode specifications and 10MHz or higher to meet the 400kHz mode specifications. |
|
|
h.a.j.molenaar
Joined: 04 May 2005 Posts: 9
|
|
Posted: Thu Aug 09, 2007 6:03 am |
|
|
It is in intended to use 400Khz bus speed.
It is not clear to me how to specify the fast = xxxx parameter. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Aug 09, 2007 6:23 am |
|
|
With the fast parameter you specify how 'fast' you want the clock speed to be.
Code: | #use i2c(Master, FORCE_HW, FAST=400000, sda=PIN_C4, scl=PIN_C3) | This sets the target speed to 400kbps |
|
|
h.a.j.molenaar
Joined: 04 May 2005 Posts: 9
|
|
Posted: Thu Aug 09, 2007 7:09 am |
|
|
Hi, I already did it after your formet comment but the strange behaviour still occurs. I am going to setup another device may be the hardware has been damaged. |
|
|
|