New i2c libraries with 'softi2c'
Moderators: adafruit_support_bill, adafruit

Re: New i2c libraries with 'softi2c'

by fat16lib on Mon Dec 26, 2011 6:23 pm

I setup the MCP230177 with a scope on SCL (yellow) and SDA (blue) and looked at TWI I2C:

hardI2C.jpg
hardI2C.jpg (101.85 KiB) Viewed 5810 times


and software I2C:

softI2C.jpg
softI2C.jpg (104.64 KiB) Viewed 5810 times

And noticed SDA was LOW after sending a byte with TWI and HIGH with software I2C.

I added the line to write and it seemed to work so I did the post with the added line.

I thought more about it and realized it was really stop() that had a problem. I did more mods, deleted the post with the added line, and posted a new version of i2cv2.zip.

You should download the new version of i2cv2.zip which is posted in the beginning of this topic.
fat16lib
 
Posts: 593
Joined: Wed Dec 24, 2008 1:54 pm

Re: New i2c libraries with 'softi2c'

by Stan12 on Fri Jul 13, 2012 1:14 am

I am using
Windows XP
Arduino IDE 1.0
Adafruit Data Logger shield on Arduino Mega 2560

I2cMaster library installed into 'libraries' folder from i2cv2.zip

When I run softDS1307 sketch (from i2cv2.zip) I have initially in Serial Monitor window:
Code: Select all | TOGGLE FULL SIZE
The current time is 07/13/2012 Thu 00:51:22
Control: 00

Options are:
(0) Display date and time
(1) Set time
(2) Set date
(3) Set Control
(4) Dump all
(5) Set NV RAM
Enter option:

time seems correct, but no options are working.

When I enter any number and hit 'send', I am always getting:
Code: Select all | TOGGLE FULL SIZE
Invalid entry
99

Invalid option

I made no modifications to softDS1307 code.
Results are the same in IDE 1.0 and 1.0.1

Is this normal or am I doing anything wrong?

i2cScanAddress sketch, when I changed to
Code: Select all | TOGGLE FULL SIZE
#define USE_SOFT_I2C 1

produces this output:
Code: Select all | TOGGLE FULL SIZE
Add read: D0
Add write: D0
Done

with USE_SOFT_I2C 0
it only shows word 'done' which means it did not find anything.
Stan12
 
Posts: 2
Joined: Fri Jul 13, 2012 12:54 am

Re: New i2c libraries with 'softi2c'

by fat16lib on Fri Jul 13, 2012 4:06 pm

I suspect you have an option other than "No line ending" enabled in the serial monitor.

This is at the bottom of the serial monitor near the baud rate selector.

The input function needs to be fixed to treat any combination of CR and LF as end-of-line.

I keep meaning to post a new version of the I2C stuff but have not found time to finish the new version. Sorry!
fat16lib
 
Posts: 593
Joined: Wed Dec 24, 2008 1:54 pm

Re: New i2c libraries with 'softi2c'

by Stan12 on Fri Jul 13, 2012 7:57 pm

fat16lib wrote:I suspect you have an option other than "No line ending" enabled in the serial monitor.

This is at the bottom of the serial monitor near the baud rate selector.

The input function needs to be fixed to treat any combination of CR and LF as end-of-line.

I keep meaning to post a new version of the I2C stuff but have not found time to finish the new version. Sorry!

Yep, you are right!
I had it set to 'Carriage Return', when switched to 'No line ending everything's fine!
May be it's worth of making a comment in softDS1307 code.
Thank you for your prompt and effective reply!!
Stan12
 
Posts: 2
Joined: Fri Jul 13, 2012 12:54 am

Re: New i2c libraries with 'softi2c'

by MichalisZ on Tue Sep 25, 2012 9:20 am

Helo, I am trying to use this library with an Arduino UNO R3 and a DS1307.
The DS1307 works fine when using std SDA and SCL ports
but I want to use different ports for SDA and SCL (A2 and A3).

I changed this
Code: Select all | TOGGLE FULL SIZE
 #define SDA_PIN 16
#define SCL_PIN 17


and set USE_SOFT_I2C to 1

However I get :

"Read Failed for display time"

when I try to display date and time.
Any suggestion? Has anyone managed to use other port for i2c communication with this sensor?
MichalisZ
 
Posts: 1
Joined: Tue Sep 25, 2012 9:15 am

Re: New i2c libraries with 'softi2c'

by fat16lib on Thu Feb 21, 2013 10:49 am

I have posted two new software I2C libraries. These libraries are at http://code.google.com/p/rtoslibs/downloads/list in the file DigitalIO20130221.zip.

This file also contains fast digital I/O classes and a fast software SPI class template.
The DigitalPin.h file contains the fastest pin I/O class and functions. These functions require a constant pin number.

These function execute in two cycle with constant arguments. On an Uno, two cycles is 0.125 usec. This is about 25 times faster than the standard Arduino digitalWrite().

The PinIO class has run time pin numbers and is four to five times faster than the standard digitalRead() and digitalWrite() functions. For pin 13 on an Uno, write() executes in about 0.8 usec and toggle() is faster. The standard Arduino digitalWrite() function takes about 4 usec.

This class saves overhead by not disabling PWM mode on each read/write call and by storing the port register addresses and pin bit mask in private variables.

The template class SoftSPI uses fast pin I/O to implement a software SPI bus at about 2 MHz.

The two classes FastI2cMaster and SoftI2cMaster implement software master mode I2C.

FastI2cMaster is a template class and runs at about 400 kHz.

SoftI2cMaster uses run time pin numbers and runs at about 100 kHz.
fat16lib
 
Posts: 593
Joined: Wed Dec 24, 2008 1:54 pm

Re: New i2c libraries with 'softi2c'

by pelrun on Thu Feb 28, 2013 10:46 am

I'm attempting to use the latest software i2c library to read a DS1307, but I'm only ever getting zeroes back from SoftI2CMaster.transfer(). My logic analyzer shows that the signals on the wire are *perfect* - I can read the date straight off the I2C analysis window, so the bits are getting lost somewhere in the library! :(

Edit: Just tried it on different pins. Same signals on the wire, but this time it works. :shock:
(for reference, before it was SCL=D12, SDA=D13, now it's SCL=D11, SDA=D12)
pelrun
 
Posts: 1
Joined: Thu Feb 28, 2013 10:04 am

Re: New i2c libraries with 'softi2c'

by stanz on Wed Jun 26, 2013 6:25 pm

If someone can point me in the right direction, I'd really appreciate it.

I'm trying to connect two UNOs with I2C. (It's more complicated - several slaves and one master eventually on the bus - but I can't get just two to talk at this point). One of these (the one that wants to be a master) has a radio attached, so SDA and SLC are tied up. SoftI2C to the rescue!! I thought.....

The two UNOs communicate just fine with <Wire.h> if I remove the radio, so at least something works. But, I need softI2C on the master. I reverse-engineered the DS1307 program and developed (I think) read and write functions to an arbitrary slave address. But, I'm having no luck with the slave even detecting (receiveEvent and requestEvent are not being triggered) any activity.

The next step is watching bits wiggle with a scope, unless someone can provide some words of wisdom. I'd think the I2C protocol would be common, and I could talk from softI2C to wire and back, but right now it doesn't look that way. Sample code for master and slave would be awesome, but any help would be greatly appreciated.

Thanks

stanz
 
Posts: 2
Joined: Sun Feb 26, 2012 11:21 pm

Re: New i2c libraries with 'softi2c'

by stanz on Thu Jun 27, 2013 12:10 am

Regarding my earlier post (above) I have
1. Added pull up resistors (thought that would do it, but no joy).
2. Tried softi2c sample programs (master) and wire sample programs (slave) with the following results:
a) i2cScanAddress, and I actually get a response from the slave. ID is 2x actual ID, but this makes sense when you look at itcScanAddress code. So it seems this shows master must be wired properly and proper pins are in use.
b) i2cScopeTest Nothing. Nada. Neither read mode or write mode. I tried both the both the slave_receiver and slave_sender from wire examples.

So at this point I've got 'standard' programs with only pin number mods. Other than getting a successful result from (effectively) rtc.start(address << 1 | IC2_WRITE) and rtc.start(address << 1 | IC2_READ) in itcScanAddress I haven't gotten anything else to work.

I'd sure appreciate a suggestion. Thanks in advance.

stanz
 
Posts: 2
Joined: Sun Feb 26, 2012 11:21 pm

Re: New i2c libraries with 'softi2c'

by adafruit_support_mike on Fri Jun 28, 2013 7:17 pm

StanZ wrote:i2cScanAddress, and I actually get a response from the slave. ID is 2x actual ID, but this makes sense when you look at itcScanAddress code. So it seems this shows master must be wired properly and proper pins are in use.

That would be correct for an I2C control byte. The top 7 bits are the device address, and the LSB is the Read/Write bit.

As for the rest, it looks like there's a fairly extensive discussion of the subject here: http://dsscircuits.com/articles/arduino ... guide.html Maybe something there can help.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 10777
Joined: Thu Feb 11, 2010 2:51 pm

Re: New i2c libraries with 'softi2c'

by phatpaul on Wed Sep 04, 2013 2:04 pm

Correct me if I'm wrong,
From looking at the code, it doesn't appear that this software I2C master supports "clock stretching".

http://www.i2c-bus.org/clock-stretching/

This may be StanZ's problem. It seems the I2C slave code relies on clock-stretching, but this software I2C master doesn't support it.

I need this feature myself, so I may modify the library to support it (not a trivial task). Let me know if it will help anyone else.
-Paul
phatpaul
 
Posts: 1
Joined: Wed Sep 04, 2013 1:55 pm

Re: New i2c libraries with 'softi2c'

by nicoverduin on Mon Sep 23, 2013 9:38 am

Anyone ported these to ATTINY yet? Or has it become my task :)
nicoverduin
 
Posts: 1
Joined: Mon Sep 23, 2013 9:37 am

Re: New i2c libraries with 'softi2c'

by adafruit_support_rick on Mon Sep 23, 2013 12:41 pm

TinyWireM
https://github.com/adafruit/TinyWireM

But thanks for volunteering, anyway :wink:

adafruit_support_rick
 
Posts: 13757
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: New i2c libraries with 'softi2c'

by ilaam on Tue May 20, 2014 4:26 am

Hi,
Can anyone tell me what is the "address" argument in the write function?
Is it different from DS1307ADDR ?
Forgive my question (I'm a beginner)
ilaam
 
Posts: 3
Joined: Tue May 20, 2014 4:24 am

Re: New i2c libraries with 'softi2c'

by adafruit_support_rick on Tue May 20, 2014 10:00 am

I'm not sure what "write" function you're referring to? There aren't any write functions in the TinyWireM library that take an address argument. Where are you looking?

adafruit_support_rick
 
Posts: 13757
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY