nox771 / i2c_t3

Enhanced I2C library for Teensy 3.x devices
156 stars 44 forks source link

Is there a way to undo the effects of Begin? #31

Open hmaarrfk opened 4 years ago

hmaarrfk commented 4 years ago

Is there a way to undo the effects of begin?

I would like to use the I2C pins as regular GPIO pins after using them as I2C pins.

Is this supported? If not, can you point me to what I would have to do to help out on that front?

Thanks!

nox771 commented 4 years ago

There is no "disconnect" routine built-in, but you can use one of the following to change the GPIO function back to normal:

pinMode(pin#, INPUT);
pinMode(pin#, INPUT_PULLUP);
pinMode(pin#, OUTPUT);

After that it should be possiible to reconnect I2C using something like: Wire.pinConfigure(SCLpin#, SDApin#);

edit: BTW, don't forget there is probably an external pullup in place, which is still there even in GPIO mode.

hmaarrfk commented 4 years ago

And I assume the driver works in polling mode? So I won't be triggering any interrupts after I use the the GPIO?

hmaarrfk commented 4 years ago

Or I guess I would have to manually disconnect from all the interrupts

nox771 commented 4 years ago

I have not tested this scenario, but the I2C should not generate interrupts if the pins are disconnected from the GPIO. If you need something more effective than you can disable I2C interrupts in I2C_C1_IICEN, and disable I2C clock in SIM_SCGCx registers (refer to begin() code).