i2c pullups

hax

New Member
Hi all,

I want to use a 5V picaxe with a 3.3v i2c device.

If I set the pullup i2c resistors to 3.3v instead of 5v I believe it should work. But I just wanted to make sure that the Picaxe works correctly in that it "pulls down" the line to communicate (as required by the standard), and never pulls up the communication pins to 5V.

Can anyone confirm this? If not, I will just measure it, but it's risky as I may blow up the chip!
 

kranenborg

Senior Member
Hi,

There should not be be a safety issue regarding 5V for the 3.3V inputs of the i2c slave device since the PIC will use only a pull-down to alter the level of the bus: the logic High level will be set by the line to which you connect the pullup resistors. However, the interpretation of a logic High level by the PIC might be an issue depending on the electrical design of the port type (Schmitt-Trigger or TTL) as well as the PIC type. For example, if your PIC will interpret 0.8*Vcc (with its Vcc being 5V) as a minimum value for interpreting it as a High logic level since you happen to use a Schmitt-Trigger input type, then this level (voltage equalling 0.8 * 5V = 4V) will never be attained on the bus (and with the effect of bus capacitances included there may be a time delay before the bus settles to a certain logic level). See the very important and useful info on the port type (Schmitt-Trigger vs. TTL) in the description of the INPUTTYPE command, which for all PICAXE chips provides info on the port type (and options to change them in case of a 14M2 or 20M2): http://www.picaxe.com/BASIC-Commands/Digital-InputOutput/inputtype/ .

A useful discussion on this item can be found here: https://www.microchip.com/forums/m33064.aspx . So the first question is: which PICAXE type do you intend to use (i.e. which PIC type does it correspond to) and which input channel?

/Jurjen
http://www.kranenborg.org/electronics
 
Last edited:

oracacle

Senior Member
is there any reason you cant run the entire circuit from 3.3v. All recent PICAXE will run quite happily at that voltage.
 

hippy

Technical Support
Staff member
the interpretation of a logic High level by the PIC might be an issue depending on the electrical design of the port type (Schmitt-Trigger or TTL) as well as the PIC type.
That's a good point; if the PICAXE pin is expecting a high level greater than the voltage SDA floats to it will never register a high.

Unfortunately it is not immediately clear what SDA's high voltage level detect level is. INPUTTYPE can be used but that only affects pins when they are used as general purpose inputs. When used for on-chip functions they may use other modes. The PICmicro data sheets lists possibilities as Schmitt (ST), TTL, CMOS, Analogue (AN), and, the less than useful here, I2C. That doesn't seem to be defined further than "Schmitt trigger input with I2C levels" and the electrical characteristics in the datasheet I looked at only define bus timing, not actual voltage levels.

The official I2C spec defines VIL as < 30% of VDD, VIH as > 70% of VDD, so, for 5V, one would expect 3.5V. But that doesn't necessarily mean the PICAXE won't register a high at some level below that.

Perhaps the best way to tell is to try it. Or, as oracacle suggests, run the PICAXE at 3.3V.
 
Last edited:

kranenborg

Senior Member
Unfortunately it is not immediately clear what SDA's high voltage level detect level is. INPUTTYPE can be used but that only affects pins when they are used as general purpose inputs. When used for on-chip functions they may use other modes.
Thanks Hippy, I did not realize this aspect, something learned here
/Jurjen
 

hax

New Member
Thanks all. This is all very good reading. I was not aware you could change the picaxe input types. I have never had to use that command.

It's not easy to change the picaxe voltage as the board is already finished. However I can run the i2c sensor on 3.6V instead of 3.3V. That is within the normal operating voltage for the part. Not a terribly neat solution, but it will work if the aim is to get the bus voltage up to 3.5v.
 

hippy

Technical Support
Staff member
It's not easy to change the picaxe voltage as the board is already finished.
It is always recommended to prototype a circuit before committing to any board design because retrospective changes will be disruptive, may be difficult, time consuming or expensive.

However I can run the i2c sensor on 3.6V instead of 3.3V. That is within the normal operating voltage for the part. Not a terribly neat solution, but it will work if the aim is to get the bus voltage up to 3.5v.
I would suggest trying it 'as is' because the VIH specification for the PICAXE SDA may not necessary be as high as 3.5V.

What is the sensor being used ? It may be that it has 5V tolerant I2C and all that is needed is to take the SDA pull-up to 5V.

Have you actually checked that any problem you are having is related to I2C voltage levels and not caused by something else ?
 

AllyCat

Senior Member
Hi,

I don't believe that you've quoted the PICaxe type, which can be significant for subtle details like this. I usually start with the base Microchip 14/20M2 data sheet as being the most complete and up to date (I don't normally use X2s) and then move to the x8M2 sheet where detail may be appropriate.

The official I2C spec defines VIL as < 30% of VDD, VIH as > 70% of VDD, so, for 5V, one would expect 3.5V. But that doesn't necessarily mean the PICAXE won't register a high at some level below that.
The (20M2) base data sheet confirms those figures in section 30.4, but the 70% is probably a "worst worst case" value so I would be very surprised if there are any problems in practice. If you really want to test with "limit" values you could raise the 3.3 volt rail a little, or reduce the PICaxe Vdd slightly with a forward diode in series with its supply rail. But perhaps the simplest "fix" might be to enable the PICaxe's "Weak Pullups" on the I2C pins (you may need to look very deeply into the data sheet or do some tests to see if they are active in I2C mode). The potential divider formed by the (~30K) weak pullup to 5v and the normal 4K7 to 3.3v could lift the voltage just enough, without exceeding any ratings.

As an aside, this all applies to the hardware I2C, but if you use bit-banging then you're back to standard Input levels (which are generally lower than the 70%). Except for the 08M2 C.2 pin (SDA) which is fixed as a ST input with a specified 80% high level (Table 1-2), that might just cause problems with bit-banged I2C.

Cheers, Alan.
 

hippy

Technical Support
Staff member
But perhaps the simplest "fix" might be to enable the PICaxe's "Weak Pullups" on the I2C pins (you may need to look very deeply into the data sheet or do some tests to see if they are active in I2C mode).
I recall testing that and it working but cannot remember which chip I actually tested, so would be worth confirming it for any particular PICAXE chip or external sensor.

As an aside, this all applies to the hardware I2C, but if you use bit-banging then you're back to standard Input levels (which are generally lower than the 70%)
That is a good suggestion.

Comparing against a bit-banged solution might also help prove any issue is an I2C voltage issue rather than anything else.
 
Top