I2C Library questions

General discussion on mikroPascal.
Post Reply
Author
Message
revans
Posts: 14
Joined: 13 Apr 2006 19:44
Location: United Kingdom

I2C Library questions

#1 Post by revans » 06 Mar 2007 14:53

I am using the mP I2C library routines to control the I2C hardware on a PIC18F4550 as the sole master device on the bus. As I am seeing some intermittent anomolous behaviour, I would be grateful for a little clarification of the way the library code operates:

1. The I2C_Start and I2C_Wr functions return an error flag. Presumably "bus busy" at time of entry to these routines is one error that is flagged, but are any other error conditions detected?

2. Do the library routines contain timeout logic to permit recovery from a bus that is stalled because of a (confused) slave device that is permanently asserting the clock-stretch condition or do they just loop indefinitely (and thereby crash the master device also)?

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#2 Post by yo2lio » 06 Mar 2007 15:14

Hi Revans

I'm using I2C library with success, on EasyPIC4 board and PIC18F452.
Be sure that you have PULL UP resistor on I2C bus !

Best regards
Florin Medrea

revans
Posts: 14
Joined: 13 Apr 2006 19:44
Location: United Kingdom

#3 Post by revans » 06 Mar 2007 16:00

yo2lio wrote: I'm using I2C library with success, on EasyPIC4 board and PIC18F452.
Thanks Florin. I am not saying that the library routines do not work in certain controlled circumstances. In fact most of the time they work for me too!

However their documentation is inadequate for my purpose.
yo2lio wrote: Be sure that you have PULL UP resistor on I2C bus !
This is not the first time I have used the I2C bus :) (but thank you for the thought)

My current project employs a P18F4550 as I2C bus master to control two dsPIC30F6012A slave devices and I am getting (very) occasional system hangs. The cause of these is probably one of the slaves but I am concerned that when this happens it is the master device that appears to crash and, at the moment, the most likely reason for this seems to be that the program is getting stuck within the mP I2C library routines. Hence my original questions.

Best regards,
Bob

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

#4 Post by janni » 08 Mar 2007 16:06

revans wrote: I am not saying that the library routines do not work in certain controlled circumstances.
Yea, the library is very basic - mostly works but it's not hard to 'hang' it. The PIC18 I2C state machine is also not perfect and in some processors it's very hard to make certain it won't block itself in specific circumstances.

picturkey
Posts: 1
Joined: 08 Apr 2007 21:09

#5 Post by picturkey » 09 Apr 2007 00:04

hi
i am also working with 18f4550, i am trying to use i2c rutine for along time. i read all datasheet of 18f4550 but what i did, i can't start to i2c modul. what didn't i make?

please help me...

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

#6 Post by janni » 09 Apr 2007 23:52

You'd have to be more specific than that.

revans
Posts: 14
Joined: 13 Apr 2006 19:44
Location: United Kingdom

#7 Post by revans » 13 Apr 2007 08:59

picturkey wrote:hi
i am also working with 18f4550, i am trying to use i2c rutine for along time.
This thread was really about the [undocumented] error-handling behaviour of the I2C master routines in the mP library.

Please note that nobody is saying that the library routines do not work. In fact with simple, well-behaved slaves [e.g. serial EEPROM devices] they are absolutely fine.
i read all datasheet of 18f4550 but what i did, i can't start to i2c modul. what didn't i make?
That is impossible to say. But you need to study the library documentation and the code examples in conjunction with the data sheet of the slave device that you are trying to use. Beyond that, much can be learnt from writing some simple test programs and monitoring the resulting SDA and SCL waveforms with an oscilloscope.
please help me...
For a general understanding of I2C bus, http://en.wikipedia.org/wiki/I2c is quite helpful and contains a link to the "original" Philips specification document.

Hope this helps,

Bob

AndAway
Posts: 29
Joined: 04 Mar 2009 16:35

#8 Post by AndAway » 09 Sep 2009 11:50

Hi forum
Well, does the library I2C_start() return any other errors than 'i2c busy' ?
For example will it return errorif there is no I2C slave connected?

AndAway
Posts: 29
Joined: 04 Mar 2009 16:35

#9 Post by AndAway » 09 Sep 2009 13:55

Edit: another questin, maybe anyone knows how to implement 'autodetect' feature to check if an I2C eeprom is connected or not (sth like plug and play i2c eeprom).

Andrew

User avatar
anikolic
mikroElektronika team
Posts: 1775
Joined: 17 Aug 2009 16:51
Location: Belgrade
Contact:

#10 Post by anikolic » 10 Sep 2009 21:15

maybe anyone knows how to implement 'autodetect' feature to check if an I2C eeprom is connected or not (sth like plug and play i2c eeprom).
Well, if you have any ideas how to do this, we'll take it into consideration. Do some research and give us your feedback.

Best regards,
Aleksandar
Web Department Manager

AndAway
Posts: 29
Joined: 04 Mar 2009 16:35

#11 Post by AndAway » 11 Sep 2009 19:44

Well, I thought that it can be done by acknowledge pooling as described in 24lcxxx datasheet but I really do not know how to do that with existing library.

Andrew

User avatar
anikolic
mikroElektronika team
Posts: 1775
Joined: 17 Aug 2009 16:51
Location: Belgrade
Contact:

#12 Post by anikolic » 21 Sep 2009 15:14

We will read more of this in the datasheet you have suggested, and give you a feedback on the results.

Thanks for your support!

Best regards,
Aleksandar
Web Department Manager

AndAway
Posts: 29
Joined: 04 Mar 2009 16:35

#13 Post by AndAway » 21 Sep 2009 18:46

Hi Forum
Aleksander, I have already posted the solution in this topic:

http://www.mikroe.com/forum/viewtopic.p ... 894bc1014c

Post Reply

Return to “mikroPascal General”