SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
By victorf
#116534
I am using 2 3V3 I2C buss devices on an Arduino Shield. One is a SFE 5843 Breakout and one is a Ramtron FM24W256 F-Ram. These devices are both 3V3 devices. Can I use these on the standard A04 and A05 pins, or are these pins for 5V devices? If they are not compatible with A04 and A05, how do I use them? I don't wish to do voltage level conversion if I can avoid it.

Vic
By esklar81
#116537
Victor,

For what are you planning on using those two pins? They are labelled as being analog inputs, although they can be used for other things.

By default, the analog input pins on a 5 V Arduino convert the applied voltage to a 10-bit representation proportional to the ratio of the applied voltage to 5 V. If you have an analog signal that's in the range of 0 to 3.3 V, you can measure it with that analog to digital converter (ADC), but you'll be "giving away" a about a third of the resolution, as the ADC will provide results in the range of 0 to [(3.3/5)*1023 = 675].

You can, however, change the analog reference voltage. I suggest you research the use of the analog inputs, starting here.

FWLIW, I do not believe A4 and A5 are the pins standardly used for I2C; I believe I2C is standardly implemented on digital pins 4 and 5. (See the same reference.)

Happy Hunting,
Eric
By follower
#116546
esklar81 wrote:FWLIW, I do not believe A4 and A5 are the pins standardly used for I2C; I believe I2C is standardly implemented on digital pins 4 and 5. (See the same reference.)
A4 and A5 are the standard pins (SDA & SCL) used for I2C, see: http://www.arduino.cc/en/Hacking/PinMapping168 Although, that Uno page doesn't really make that clear.

--Philip;
Last edited by follower on Mon Jan 03, 2011 7:26 pm, edited 1 time in total.
By victorf
#116547
From the Arduino Wire Library reference

"This library allows you to communicate with I2C / TWI devices. On most Arduino boards, SDA (data line) is on analog input pin 4, and SCL (clock line) is on analog input pin 5. On the Arduino Mega, SDA is digital pin 20 and SCL is 21."

BTW: I am not using a Mega

Vic
By MichaelN
#116548
victorf wrote:I am using 2 3V3 I2C buss devices on an Arduino Shield.
I'm not familiar with Arduino, but if it is really I2C you should have no problem. Put pullup resistors on the SDA and SCL lines to 3.3V; the voltage levels will be valid for both 3.3V and 5V devices. Just make sure you don't set those pins on the Arduino as outputs and drive them high, as this could indeed damage the devices powered by 3.3V.
By esklar81
#116551
@follower:
Well, that's why i say "For What Little It's Worth". :wink: In my own defense, I point out that the Arduino site does say:
"* I2C: 4 (SDA) and 5 (SCL). Support I2C (TWI) communication using the Wire library."
The photograph on that page shows an Uno with digital pins marked with numbers (including "4" and "5") with no alphabetic prefices for the digital pins and numbers (including "4" and "5") with "A" prefices for the analog input pins.

@MichaelN:
I'm a bit confused (Yeah, I know, there's a shocker. :wink: ) by:
"I'm not familiar with Arduino, but if it is really I2C you should have no problem. Put pullup resistors on the SDA and SCL lines to 3.3V; the voltage levels will be valid for both 3.3V and 5V devices. Just make sure you don't set those pins on the Arduino as outputs and drive them high, as this could indeed damage the devices powered by 3.3V."
I can see how your approach would work if all one wanted to do with the Arduino is read from the I2C, as 3.3 V should be read as a 1 by a digital input (including an analog input port being operated as a digital input) of the Arduino. What I don't see is how you could write to the I2C (or output clock pulses, for that matter) without setting the Arduino pins to HIGH and, thereby, putting 5 V on them if one is using a 5 V Arduino. Care to enlighten me or point me at an explanation somewhere?

TIA,
Eric
By MichaelN
#116557
esklar81 wrote:@MichaelN:
I'm a bit confused (Yeah, I know, there's a shocker. :wink: ) by:
"I'm not familiar with Arduino, but if it is really I2C you should have no problem. Put pullup resistors on the SDA and SCL lines to 3.3V; the voltage levels will be valid for both 3.3V and 5V devices. Just make sure you don't set those pins on the Arduino as outputs and drive them high, as this could indeed damage the devices powered by 3.3V."
I can see how your approach would work if all one wanted to do with the Arduino is read from the I2C, as 3.3 V should be read as a 1 by a digital input (including an analog input port being operated as a digital input) of the Arduino. What I don't see is how you could write to the I2C (or output clock pulses, for that matter) without setting the Arduino pins to HIGH and, thereby, putting 5 V on them if one is using a 5 V Arduino. Care to enlighten me or point me at an explanation somewhere?
I2C is an open-drain bus, which means the devices don't actually drive the lines high (that is achieved with a pull-up resistor). Devices on the bus actively pull the lines low, but not high. As stated, pulling up the lines to 3.3V with a pull-up resistor will still be read as a valid logic “1” by devices powered with 5V.

Usually you will use an inbuilt I2C module in the microcontroller, which takes most of the hassle out of bit-bashing it. If you do need to bit-bash, you need to be very careful what you do with the registers controlling the pins. You first need to write a logic “0” to the pins used for I2C, and then DO NOT CHANGE IT. To write a logic “1” to a pin, you change the Data Direction Register for that pin to make it an INPUT – the pull-up resistor will then pull the line high. To write a logic “0” to the pin, you change the Data Direction Register for that pin to make it an OUTPUT.

Hopefully that’s not too confusing…
By follower
#116558
esklar81 wrote:In my own defense, I point out that the Arduino site does say:
"* I2C: 4 (SDA) and 5 (SCL). Support I2C (TWI) communication using the Wire library."
Hee, hee, it doesn't anymore. :) (Thanks to an extremely fast turn around on this bug report.)

But I'm glad you pointed it out originally so it could get fixed for everyone.

--Philip;
By follower
#116559
MichaelN wrote:Hopefully that’s not too confusing…
Nope, that was great! I definitely learned from it--thanks for taking the time to write the explanation.

--Philip;