PDA

View Full Version : I2C with any PIC?



flotulopex
- 19th April 2007, 14:57
Hello,

I'm not used to handle I2C communication.

In several datasheets, I've seen some specific information about the I2C capability of this or that chip.

My question is: what makes the difference between PICs that have a I2C capacity described in their datasheet and the other ones that don't?

(...i just have the feeling my question is not clear enough...)

sougata
- 19th April 2007, 15:41
Hi,

PBP uses a software based I2C so it does not actually matter if your chip has an onboard hardware I2C. It will never use it.

flotulopex
- 19th April 2007, 20:41
Thanks Sougata,

This is what I thought since I use a 12F675 and a 24LCxxx memory via I2C and this PIC has no specific I2C interface (...and, of course, it works).

So what is the "advantage" or simply the reason for certain PICs to have a I2C interface?

mister_e
- 19th April 2007, 20:57
well, usually faster than most software solution, usually provide interrupts triggers, etc etc etc. Same for USART (HSERIN/HSEROUT) against SEROUT/SERIN etc etc.

BigWumpus
- 20th April 2007, 22:47
...just try to code a slave-I2C !

Then you will see, what advantages a hardware-modul can give to you !

...and it gives you so much performance, if you use the hardware in an intelligent way!

skimask
- 21st April 2007, 00:56
...just try to code a slave-I2C !

Then you will see, what advantages a hardware-modul can give to you !

...and it gives you so much performance, if you use the hardware in an intelligent way!

Somewhere out there, is a site with practically complete I2C-slave code, uses the hardware and PBP to handle things. Apparently it works like a champ. A 2nd PIC18F452 is slave-I2C programmed to act just like a 24LC256 and it's accessed by the 1st 18F452 using PBP's I2C commands. Wish I remembered where that was...

Melanie
- 21st April 2007, 09:07
Many of us have done this but for professional reasons we are unable or unwilling to share the code. However, Robert Soubie detailed his adventures with I2CSlave using Melabs PICBasic, and posted all his code here...

http://www.astrosurf.com/soubie/pic_as_an_i2c_slave.htm

Well done Robert!

ralfmayr
- 19th November 2008, 11:47
Hi Melanie,
i tried Roberts I2C Slave routine, but it is not clear how to access the Slave with I2CREAD / I2CWRITE with Melabs PBP from the Master.
In the I2CREAD and I2CWRITE commands are also "address" parameters given, is this the same to be used as the parameter RXBuffer(0)?
Does any one have an exmaple for me?
Regards,
Ralf

Melanie
- 19th November 2008, 13:58
Other than telling you that Robert achieved the goal that many seek but few accomplish, and he documented everything on his website (I'm assuming it's all still there), I can't add any more, because I haven't actually tried his software myself.

ralfmayr
- 19th November 2008, 17:25
Hello Melanie,
yes there is a lot on the website, but there is not describd how to access it with I2CREAD / I2CWRITE. May be i am blind.... Maybe anyone else can help...?
Regards,
Ralf

Archangel
- 19th November 2008, 17:39
Hello Melanie,
yes there is a lot on the website, but there is not describd how to access it with I2CREAD / I2CWRITE. May be i am blind.... Maybe anyone else can help...?
Regards,
Ralffrom the second page of his web site:
http://www.astrosurf.com/soubie/fichiers/i2cInt.pbp
http://www.astrosurf.com/soubie/fichiers/Proc_i2c.pbp

Melanie
- 19th November 2008, 18:19
You would still use I2CREAD and I2CWRITE as per normal in the Master PIC. It's only the slave PIC that would use the new routines.

ralfmayr
- 19th November 2008, 19:01
Hello Melanie,
hello Joe,
thanks for your answers.
I have the code from Robert, i also implemented his code in my interrupt
service of the slave (a 2431), all no problem, but:
The problem i have is that i do not understand how it works. When writing or reading with my master (a 6722) to / from the slave, i alwasy get sensless values from the slave. The slave routine from Robert waits for 3 RXbuffer values (0 - 2), the first value of RXBuffer(0) indicates in i2c_proc.pbp the var-id, all other two bytes are the values. But when writing three values with I2CWRITE sda, scl, addr, [b1, b2, b3], the service routine gives back "0" for all two TX Values (defined in the i2c_proc.pbp there have been other values defined).
In the pbp manual, there is also a value possible behind the address (before the "[", but using this value also for the RXBuffer(0) results also in senseless values.
So i think the I2CREAD / I2CWRITE command i use in a wrong way, so i am looking for a master code example, which controls a slave to see the correct usage.
Uff..... understood?
BR
Ralf