New Wire library is not supporting all of the valid SCL/SDA pins

KurtE

Senior Member+
I was taking a look through the new Wire library (WireKinetis.cpp/h) and noticed that the new library is not supporting all of the valid SCL/SDA pins that the previous version was.

In particular it is only supporting those pins that have mux(2)...

If you look at the removed code, in this case: for the main Wire Object.
Code:
-void TwoWire::setSDA(uint8_t pin)
-{
-	if (pin == sda_pin_num) return;
-	if ((SIM_SCGC4 & SIM_SCGC4_I2C0)) {
-		if (sda_pin_num == 18) {
-			CORE_PIN18_CONFIG = 0;
-		} else if (sda_pin_num == 17) {
-			CORE_PIN17_CONFIG = 0;
-#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
-		} else if (sda_pin_num == 34) {
-			CORE_PIN34_CONFIG = 0;
-		} else if (sda_pin_num == 8) {
-			CORE_PIN8_CONFIG = 0;
-		} else if (sda_pin_num == 48) {
-			CORE_PIN48_CONFIG = 0;
-#endif	
-		}
-
-		if (pin == 18) {
-			CORE_PIN18_CONFIG = PORT_PCR_MUX(2)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE;
-		} else if (pin == 17) {
-			CORE_PIN17_CONFIG = PORT_PCR_MUX(2)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE;
-#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
-		} else if (pin == 34) {
-			CORE_PIN34_CONFIG = PORT_PCR_MUX(5)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE;
-		} else if (pin == 8) {
-			CORE_PIN8_CONFIG = PORT_PCR_MUX(7)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE;
-		} else if (pin == 48) {
-			CORE_PIN48_CONFIG = PORT_PCR_MUX(2)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE;
-#endif	
-		}
-	}
-	sda_pin_num = pin;
-}
-
-void TwoWire::setSCL(uint8_t pin)
-{
-	if (pin == scl_pin_num) return;
-	if ((SIM_SCGC4 & SIM_SCGC4_I2C0)) {
-		if (scl_pin_num == 19) {
-			CORE_PIN19_CONFIG = 0;
-		} else if (scl_pin_num == 16) {
-			CORE_PIN16_CONFIG = 0;
-#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
-		} else if (scl_pin_num == 33) {
-			CORE_PIN33_CONFIG = 0;
-		} else if (scl_pin_num == 7) {
-			CORE_PIN7_CONFIG = 0;
-		} else if (scl_pin_num == 47) {
-			CORE_PIN47_CONFIG = 0;
-#endif	
-		}
-
-		if (pin == 19) {
-			CORE_PIN19_CONFIG = PORT_PCR_MUX(2)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE;
-		} else if (pin == 16) {
-			CORE_PIN16_CONFIG = PORT_PCR_MUX(2)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE;
-#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
-		} else if (pin == 33) {
-			CORE_PIN33_CONFIG = PORT_PCR_MUX(5)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE;
-		} else if (pin == 7) {
-			CORE_PIN7_CONFIG = PORT_PCR_MUX(7)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE;
-		} else if (pin == 47) {
-			CORE_PIN47_CONFIG = PORT_PCR_MUX(2)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE;
-#endif	
-		}
-	}
-	scl_pin_num = pin;
-}

You will see there are casws for Mux 5 and Mux 7 which are not built into your new tables.

Looks like the table code should support it as you have pin number and mux numbers in the table.

If desired I can take a pass and add, and do Pull request.
 
Actually it looks like I missed reading the tables and most if not all are there. Will see if I find any missed.

Sorry
 
Thanks, the only ones I found so far was:

On Wire1 (t3.5/6) Pins 58 (mux 6)/59(Mux6) on SDCArd adapter can be used.

I have not tried running it. But it does make for fun to have simple sdcard adapter with I2C display connected...
 
someone should make a list of differences between wire (arduino), i2c_t3, and pauls wire library, such as features, recovery, speeds, interrupts, etc
 
Wire is a bit of moving target right now. Aside from these seldom-used pins and the static initialization order bug recently reported, I'm planning to add non-blocking master mode support. The API is still being discussed with the Arduino devs.
 
someone should make a list of differences between wire (arduino), i2c_t3, and pauls wire library, such as features, recovery, speeds, interrupts, etc
To my question: Since I use a Teensy 3.2, I use "i2c_t3". Is the new "Wire" intended as a replacement for "i2c_t3" or what should I use better?
 
Paul, can answer this better than I can, but:

i2c_t3 is a nice Teensy specific library to handle the I2C buss, and has a lot of nice features. I believe it supports DMA, some error recovery

Wire is the original Arduino library to deal with I2C buss. Paul's more recent version made our version of Wire more compatible with some of the other Wire libraries out there for processors that support multiple Wire busses. That is they they are all derived from one class. Hopefully with that libraries that use Wire library can be updated to allow a pointer or reference to which Wire object to use and be able to support any of them.

Both libraries allow you to use alternate pins for SCL/SDA, however they do it differently. i2c_t2 has some fixed configurations you specify for which pin combinations you wish to use. Wire library allows you to specify them to any valid ones using calls like: Wire.setSCL(pin), Wire.setSDA(pin).

I know that I2C_t3 has some support for detecting error conditions and recovery. I know Paul was adding some to the new version of Wire. Which one is better at that? I don't know hopefully one of the others will chime in.
 
i2c_t3 still offers more functionality. Wire has been slowly improving, and that trend will continue over the next few releases. If you want the most capability right now, use i2c_t3.
 
Hello,

Using teensy 3.2 and trying to use SCL1/SDA1 (pins 29/30), I believed to find 29 and 30 in the part of code discussed. Anybody can me explain how it works for this second i2c bus? regards
 
Ok, I understand now I need to use i2c_t3 lib.
Can I found somewhere a "port" to Wire1 for Adafruit_INA219 lib?
I am starting the job.
 
Not sure what else is in the system or what the INA219 is - but for Adafruit displays moving from Wire to Wire1 requires just putting that '1' on the calls.

When I did it for a display I was using I just did: "#define Wire Wire1"

It seems that was in the header file of the library. That fixed it in the code - there was a second part that the compiler may point out as needed.
 
Back
Top