Go Down

Topic: Wire.h and pin 13 (Read 5 times) previous topic - next topic


> I think that you have to do this just on your "master" board

It doesn't matter where exactly you place the resistors between +5V and the I2C "backbone", it just needs to be done somewhere on the I2C bus.


Nov 22, 2006, 01:09 pm Last Edit: Nov 22, 2006, 01:15 pm by fux Reason: 1
here is my setup how I connect two boards over the i2c interface. note that the resistors goes from the two wires to the 5+ pin of the board. in this setup the left board is the "master" and the right one the "slave".


Nov 22, 2006, 04:49 am Last Edit: Nov 22, 2006, 04:56 am by landon Reason: 1
I'm using Mac OSX and I don't get the problem when I include Wire.h.

I am using an Arduino Ministamp, though, so that might be a difference.

However, when I do a Wire.begin(), it hangs.

I have pull-ups on the I2c bus (I'm using 10K's...not sure what values to use with the Arduino Mini).  It hangs with or without pullups.

Also, I started reading the wire code and am concerned that it may not work at all with the Mini.  Has anyone got I2c working with the Mini?

I have a working LCD on my setup and use it for debug.  I'm trying to set up to talk to the Sparkfun real time clock device on I2C.

Code: [Select]
#include <stdio.h>
#include <LiquidCrystal.h>
#include <Wire.h>

LiquidCrystal lcd = LiquidCrystal();

int loopct = 0;

// based on SFE Pic code, the RT device address is 0xD0

void setup( void )
 digitalWrite(13, HIGH);  // turn on debug LED  


 lcd.printIn("Wire init done");

In the case above, I see "Wire.begin()" but it never displays  "Wire init done".  It seems to hang in the Wire.begin().

So, I started looking through the wire and twi code.   One of the things that concerns me is this:

Code: [Select]
void twi_init(void)
 // initialize state
 twi_state = TWI_READY;

 #ifdef ATMEGA8
   // activate internal pull-ups for twi
   // as per note from atmega8 manual pg167
   sbi(PORTC, 4);
   sbi(PORTC, 5);
   // activate internal pull-ups for twi
   // as per note from atmega128 manual pg204
   sbi(PORTD, 0);
   sbi(PORTD, 1);

From what I can tell the internal pull-ups on an Atmega168 (arduino mini) is on PORTB.  Given the comments in the code re: Atmega128 and this is the default if it's not an Atmega8, it makes me think the Wire interface has not yet been ported to work with the Mini.

I've put a scope on the Arduino mini ADC4 and ADC5 ports and never see any activity with Wire.begin().  These ports are not pinned out - I soldered a small female breakaway header to the ADC4 and ADC5 ports so I could access them.

Again, I have doubts that the Wire library and the Mini are currently compatible.  Has anyone else researched this or succeeded with the I2C/TWI interface on the Mini?

But back to the thread - I can include Wire.h without a hang, but it is potentially because I'm using a Mini and Wire is hosed for an Arduino Mini (I suspect.)


Nov 21, 2006, 09:05 pm Last Edit: Nov 22, 2006, 01:36 pm by fux Reason: 1
When you connect the board with the two wires (analog 4+5) plus one resistor for each wire to the 5+ of your board, the problem you descriped should be fixed. on XP my sketch doesn't hang up even if I leave the resistors, but on a mac I just got it runnin with the resistors (that's really weird). I think that you have to do this just on your "master" board, so for example if you use a second board as a "slave" you just have to put the two wires in the analog inputs 4+5, but I am not really sure about that. the "master_writer" sketch now works on my board, but the "slave_receiver" sketch on a second board hangs up.


// Wire Slave Receiver
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this

#include <Wire.h>

void setup()
 Wire.begin(4);                // join i2c bus with address #4
 Wire.onReceive(receiveEvent); // register event
 Serial.begin(9600);           // start serial for output

void loop()

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
 while(1 < Wire.available()) // loop through all but the last
   char c = Wire.receive(); // receive byte as a character
   Serial.print(c);         // print the character
 int x = Wire.receive();    // receive byte as an integer
 Serial.println(x);         // print the integer

it seems that the function "receiveEvent" causes problems, because when one byte is received it hangs up. has anyone an idea, what could be the problem?




Nov 21, 2006, 05:59 pm Last Edit: Nov 21, 2006, 06:00 pm by brainfart Reason: 1
> Haven't tried with the resistors yet

You should! The I2C bus won't work without them. Dedicated I2C hardware might already have them built in, but the Arduino definitely doesn't.

Go Up