How to enable pullups on I2C lines when using Wire.h?

paynterf

Well-known member
In past projects I have used the i2c_t3.h library, and noticed that for the cable lengths I have been using (10-20cm), no pullup resistors were required when using:


Wire.begin(I2C_MASTER, 0x00, I2C_PINS_18_19, I2C_PULLUP_INT, 400000);

But when I use the Wire.h library, external pullups are always required.

Clearly the i2c_t3.h library is doing some 'magic' in the background to enable pullups on the I2C pins, and just as clearly the Wire.h library is not. There must be some way to enable them manually when using the Wire.h library, but I can't seem to figure it out.

Looking through other posts and the 'K20 Sub-Family Reference Manual' I thought the following should work to enable internal pullups on pins 37/38 (Wire1) when placed just before 'Wire1.begin()'.


for (uint8_t pin = 37; pin <= 38; pin++)
{
* portConfigRegister(pin) |= PORT_PCR_PE; //pull enable
*portConfigRegister(pin) |= PORT_PCR_PS; //pull up
}

but AFACT this does nothing; external pullups are still required. What am I doing wrong here?

Anyone know how to do this?

TIA,

Frank
 
Back
Top