Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 17 of 17

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

  1. #1
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,499

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

    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.

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,499
    Actually it looks like I missed reading the tables and most if not all are there. Will see if I find any missed.

    Sorry

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,774
    I could have missed some. I did test them all, but I made the list of tests from the tables....

  4. #4
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,499
    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...

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,774
    Oh, yeah, I didn't consider the SD card pins. Will add that on the next rev...

  6. #6
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,610
    someone should make a list of differences between wire (arduino), i2c_t3, and pauls wire library, such as features, recovery, speeds, interrupts, etc

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,774
    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.

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,774
    Quote Originally Posted by KurtE View Post
    On Wire1 (t3.5/6) Pins 58 (mux 6)/59(Mux6) on SDCArd adapter can be used.
    How's this look?

    https://github.com/PaulStoffregen/Wi...bca6414ea73da4

  9. #9
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,499
    Looks like it should work

  10. #10
    Junior Member
    Join Date
    Oct 2016
    Posts
    11
    Quote Originally Posted by tonton81 View Post
    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?

  11. #11
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,499
    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.

  12. #12
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,774
    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.

  13. #13
    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

  14. #14
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,494
    On T_3.2 it requires calls to Wire1() [ not Wire() ] to use those pins for the second I2C bus:
    // Wire1 3.1/3.2 I2C_PINS_29_30 29 30

  15. #15
    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.

  16. #16
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,494
    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.

  17. #17
    Quote Originally Posted by defragster View Post
    When I did it for a display I was using I just did: "#define Wire Wire1"
    Good tips. Thanks.
    I used this initialisation :
    Code:
      Wire1.begin(I2C_MASTER, 0x0, I2C_PINS_29_30, I2C_PULLUP_INT, 100000); // address ignored for Master mode ; I did not add external pull up for master but adafruit add 10k pull up to ina219
    and this doc : https://forum.pjrc.com/threads/21680...ry-for-Teensy3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •