Pages: [1]   Go Down
Author Topic: New I2C Master library  (Read 6676 times)
0 Members and 1 Guest are viewing this topic.
Worcester, MA
Offline Offline
God Member
*****
Karma: 3
Posts: 623
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Anyone interested in trying a new I2C master library for the Arduino?  I got tired of trying to modify the TWI library to get the repeated start feature to work so I went ahead and wrote a new library that combines the Wire and TWI libraries into one.  It has more functionality, higher throughput and reduced code size.  It's available for download here http://www.dsscircuits.com/images/code/I2C.zip and there's a full write up about it here http://www.dsscircuits.com/articles/arduino-i2c-master-library.html

I've tested it on several devices and so far it works well. 

Let me know what you think.
Logged

I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

0
Offline Offline
Full Member
***
Karma: 0
Posts: 140
Arduino for HiFi
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Very nice. Although the current Arduino I2C library works for me (single reads to a register), I thought it was kind of "klunky" the request operation.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi wayneft. Just to let you know i am now using your i2c library on my lighting controller.  Not too worried about the speed, using bitbanged Pic as slaves so max clock frequency they can handle is about 20kHz but was having problems with bus hanging.  Your timeout routine seems to work well. 
Also looking at using the write routine return codes to initiate retry if required
Will let you know how it goes
Wil
Logged

Worcester, MA
Offline Offline
God Member
*****
Karma: 3
Posts: 623
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Great. Let me know if you have any problems.
Logged

I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Some more examples would be nice. I'm trying to read blocks of registers from the MPR121 capacitive touch sensor controller (which needs repeated starts) and would have appreciated examples demonstrating more of the api. I'll let you know how it goes, I'm about to wake up I2C and see if it can get some data...
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can report that I was able to use I2c to read all, or chunks of registers from the mpr121 - thank you. A suggestion would be to alter the header file such that the arguments are named instead of just typed however. While coding I was reading the api docs on your site, and copying and pasting relevant lines into my own code. The compilation failed however, due to data type differences between my arguments, and those specified by the I2c api. So I looked into the header file to see what I needed to alter - and because the arguments weren't named (just typed) I found it difficult to figure out which function matched the api docs, thus I had to look at the source code which took additional time. Another suggestion would be to include the html page with the api docs inside the library folder for easy reference.

Thanks for the effort, you saved me a lot of time. I'd already burned about 12 hours finding out that the wire library wasn't going to work and yours was the third library I tried. The third pass was the charm. Thanks.
Logged

Worcester, MA
Offline Offline
God Member
*****
Karma: 3
Posts: 623
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Glad to hear it worked out for you.

Quote
and because the arguments weren't named (just typed)
I'm not sure what you mean by this.  I must tell you that I'm more of a hardware guy than software but I am trying to increase my coding skills.  So any pointers you have please feel free to pass them on.  Anything I can do to improve the library I'm happy to do.
Logged

I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

Guildford, UK
Offline Offline
Full Member
***
Karma: 0
Posts: 217
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The function prototype in the header file can contain the variable names used in the function definition. This was a change introduced with ANSI C. It sounds like you're using the older K&R C standard. Here's an example:
Code:
void MyFunction(int x, int y, char* message)
{
    ...
}

In K&R C you would prototype the function like this:
Code:
extern void MyFunction(int, int, char*);

In ANSI C you would prototype the function like this:
Code:
extern void MyFunction(int x, int y, char* message);

The ANSI C style has the advantage that you can use copy and paste to create the declarations from your function definition AND anyone viewing your headers can tell that the first parameter is x and the second y, rather than having to find the function definition.
Logged

Richmond, Virginia
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Wayneft,

Thanks so much for your library. I'm having some trouble implementing it though. Can you or anyone take a look at my code and tell me what I'm missing? What I could really use is an example that displays what goes on the master arduino and what goes on the slave arduino. At the moment I just want monitor to display some text from the slave arduino. Below is my code.

I want to do exactly this, but with your library: http://arduino.cc/en/Tutorial/MasterReader

Thanks so much in advance!

- John

MASTER:
Code:
#include <I2C.h>

void setup()
{
Serial.begin(9600);
I2c.begin();
//I2c.setSpeed(1);
//I2c.scan();

}

void loop()
{
I2c.read(0x7F,0,8);
Serial.println(I2c.available());
while (I2c.available())
{
Serial.print(">>"); Serial.println(I2c.receive());
}
}

SLAVE:
Code:
#include <I2C.h>

void setup()
{
  Serial.begin(9600);  // start serial for output
  I2c.begin();
  I2c.write(0x7F,3,3);
}
 
void loop()
{
  Serial.println(I2c.available());
  while (I2c.available())
{
  Serial.print("HI");
}
}
« Last Edit: May 13, 2014, 02:10:58 pm by jmcclaire » Logged

Creative Technologist at The Martin Agency

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Wayneft,

Thanks so much for your library. I'm having some trouble implementing it though. Can you or anyone take a look at my code and tell me what I'm missing? What I could really use is an example that displays what goes on the master arduino and what goes on the slave arduino. At the moment I just want monitor to display some text from the slave arduino. Below is my code.

I want to do exactly this, but with your library: http://arduino.cc/en/Tutorial/MasterReader

Thanks so much in advance!

- John

MASTER:
Code:
#include <I2C.h>

void setup()
{
Serial.begin(9600);
I2c.begin();
//I2c.setSpeed(1);
//I2c.scan();

}

void loop()
{
I2c.read(0x7F,0,8);
Serial.println(I2c.available());
while (I2c.available())
{
Serial.print(">>"); Serial.println(I2c.receive());
}
}

SLAVE:
Code:
#include <I2C.h>

void setup()
{
  Serial.begin(9600);  // start serial for output
  I2c.begin();
  I2c.write(0x7F,3,3);
}
 
void loop()
{
  Serial.println(I2c.available());
  while (I2c.available())
{
  Serial.print("HI");
}
}

Hello. did you find out what was wrong?
Logged

Pages: [1]   Go Up
Jump to: