Go Down

Topic: Will there ever be a SoftI2C Library? (Read 1 time) previous topic - next topic

frazras

Since there is a soft serial, is there any plans for softI2C?
How difficult/important is it to bit bang the I2C protocol? I have seen applications where it is needed, eg. to utilize 2 wiimotes, where changing the address is difficult. I have a few other applications but I was wondering if it is the community's list of priorities.

Nachtwind

Hm.. i am not quite sure about this, but have you ever looked into the twi.c? as far as i understand it there the pins for the twowire protocol are defined, maybe by copying the library and doing the neccessary changes one could add a second or maybe a third i2c portpair to the arduino.. but i am more than unsure about it...
also i stumbled upon a library (http://jump.to/fleury) for I2C on an Atmel.. maybe this may help you about this whole subject.
Believe me, Mike, I calculated the odds of this succeeding against the odds I was doing something incredibly stupid[ch8230] and I went ahead

acleone

twi.c and Peter Fleury's library both use the hardware module.  I'm currently trying to sniff some i2c traffic, and was planning on writing a softi2c kind of library when I got a chance.

frazras

OK I am Interested in writing the softI2C, I would would liek to know who assisted in the actual I2C or anyone who has knowledge to help me bit bang it. People with Soft Serial knowledge would also be great. Any takers?

acleone

The atmega168 datasheet has a pretty good explanation of the physical protocol.  I have my sniffer working, but it uses the hardware SPI module and an INT pin - not exactly SoftI2C.

Do you just need master mode, or will the Arduino be addressed as a slave too?

nukalur

This is an app note and project source from Atmel on how to implement software i2c in assembly.

http://www.avrfreaks.net/index.php?func=viewItem&item_id=75&module=Freaks%20Tools

take it for what its worth

bohne

Do you need I2C master or slave in software?
What devices must this software-I2C-lib talk to?

I guess that a TWI master is very easy, simply create the START condition with two pins, then use shiftOut(dataPin, clockPin, bitOrder, value) to write the 7bit address and r/w bit, followed by 8bit data and then create the STOP condition on the two pins...

Receiving data is another topic.
http://www.dorkbot.de
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1236434254
http://www.luminet.cc

jcw

There's a TWI bit-banging master in my Ports library, at:
  http://code.google.com/p/jeelab/source/browse/trunk#trunk/libraries/Ports
Look in Ports.h and Ports.cpp for the PortI2C and DeviceI2C classes (you can define multiple devices on one Port).

The PortsBMP085.* files contain an example of their use as described here:
   http://jeelab.equi4.com/2009/02/19/hooking-up-a-bmp085-sensor/

Not sure it's of any use, but feel free to use/re-use/alter as you like.

-jcw

Cross

I don't know what exact features you need, but I posted a modified i2c (master) library here, which might be easier to hack. It still uses the hardware i2c module though :
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1175112203/10#10

frazras

My purpose for soft I2c is actually just master, I am building a robotics kit that may use multiple sensors with similar non-modifiable i2c addresses. In fact it is the Lego Mindstorms NXT robotics kit sensors - primarily the Ultrasonic sensor for now. So hopefully this I2C master should do the trick!
Having a slave would be pretty interesting as to the capabilities i would be able to do hmmmm - chain robots - communicating over I2C :P

jcw

FWIW, the links in my March post have changed to:
   http://code.google.com/p/jeelabs/source/browse/trunk#trunk/libraries/Ports
and
   http://news.jeelabs.org/2009/02/19/hooking-up-a-bmp085-sensor/

(so much for trying to maintain valid links all over the web...)

-jcw

Go Up