New i2c libraries with 'softi2c'

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
stan12
 
Posts: 11
Joined: Fri Jul 13, 2012 12:54 am

Re: New i2c libraries with 'softi2c'

Post by stan12 »

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!!

MichalisZ
 
Posts: 1
Joined: Tue Sep 25, 2012 9:15 am

Re: New i2c libraries with 'softi2c'

Post by MichalisZ »

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

 #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?

User avatar
fat16lib
 
Posts: 595
Joined: Wed Dec 24, 2008 1:54 pm

Re: New i2c libraries with 'softi2c'

Post by fat16lib »

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.

pelrun
 
Posts: 1
Joined: Thu Feb 28, 2013 10:04 am

Re: New i2c libraries with 'softi2c'

Post by pelrun »

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)

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

Re: New i2c libraries with 'softi2c'

Post by stanz »

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

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

Re: New i2c libraries with 'softi2c'

Post by stanz »

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.

User avatar
adafruit_support_mike
 
Posts: 67391
Joined: Thu Feb 11, 2010 2:51 pm

Re: New i2c libraries with 'softi2c'

Post by adafruit_support_mike »

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.

phatpaul
 
Posts: 1
Joined: Wed Sep 04, 2013 1:55 pm

Re: New i2c libraries with 'softi2c'

Post by phatpaul »

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

User avatar
nicoverduin
 
Posts: 3
Joined: Mon Sep 23, 2013 9:37 am

Re: New i2c libraries with 'softi2c'

Post by nicoverduin »

Anyone ported these to ATTINY yet? Or has it become my task :)

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: New i2c libraries with 'softi2c'

Post by adafruit_support_rick »

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

But thanks for volunteering, anyway :wink:

ilaam
 
Posts: 3
Joined: Tue May 20, 2014 4:24 am

Re: New i2c libraries with 'softi2c'

Post by ilaam »

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)

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: New i2c libraries with 'softi2c'

Post by adafruit_support_rick »

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?

ilaam
 
Posts: 3
Joined: Tue May 20, 2014 4:24 am

Re: New i2c libraries with 'softi2c'

Post by ilaam »

I am in the I2cMaster library. It is linked in the home page.
Sorry, I didn't explain what I want. I am precisely in the softDS1307 example which come with the I2cMaster library.
That's the header of te function I working on :

Code: Select all

uint8_t readDS1307(uint8_t address, uint8_t *buf, uint8_t count)
I don't know what does the first argument stand for but I am sure that it is not the device DS1307 address since the latter is already declared as a global variable.

Code: Select all

 if (!rtc.start(DS1307ADDR | I2C_WRITE)) return false;
  if (!rtc.write(address)) return false;
  if (!rtc.restart(DS1307ADDR | I2C_READ))return false;
  for (uint8_t i = 0; i < count; i++) {
    buf[i] = rtc.read(i == (count-1));
  }
  rtc.stop();
  return true;

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: New i2c libraries with 'softi2c'

Post by adafruit_support_rick »

I don't know that library - I've never used it. But I had a look at it, and it appears that the address field in the write is the 7-bit slave address.

ilaam
 
Posts: 3
Joined: Tue May 20, 2014 4:24 am

Re: New i2c libraries with 'softi2c'

Post by ilaam »

ok.. thanks a lot.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”