2
\$\begingroup\$

I am working with the EFR32MG24 Wireless SoC Family. There is a controller and multiple sensors with custom cables and connectors. For flexibility it would be desirable to connect the cable two ways, i.e. by rotating the connector and thus swapping some cables.

Currently there are 5 connections aligned in a line as follows:

o    o   o   o   o
GND SCL  V+ SDA GND

by rotating the connector cable by 180°, V+ and GND would still work but SCL/SDA would be swapped, thus the question. Note however, that the ports could be configured differently, but there are only 4 cables but 5 connections due to a previous SYNC cable not used anymore.

Now let's say there are two GPIO Pins, C05 and C06 to which the two I2C cables are connected. I am wondering, whether it is possible to somehow detect if e.g. SCL is connected to C05 and SDA to C06 or if it is vice versa.

An approach would be to just route them one way and test if works (potentially with some configuration communication) and if not, reset I2C and reroute the pins.

Another idea is as they are connected via GPIO, listen to one pin and detect, whether this one is the Clock or not.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ I deleted my comments since they are no longer needed. And thank you, you got it right right away. About your question, in question.. why not use keyed connectors? I mean sure it sounds like a fun feature with auto detection, but the circuit gets more complicated and thus, more prone to have errors. \$\endgroup\$
    – MiNiMe
    Nov 23, 2023 at 8:33
  • \$\begingroup\$ The sensors are rather small in size and with the current design there is no space to add keyed connectors. They would require a redesign of the whole sensor module and the small size is a design requirement. \$\endgroup\$ Nov 23, 2023 at 9:14
  • \$\begingroup\$ I hear you. How are they being connected now? If you want, you could add a picture and with something as reference to their size as well. \$\endgroup\$
    – MiNiMe
    Nov 23, 2023 at 9:19
  • \$\begingroup\$ I hope this edit clarifies it. \$\endgroup\$ Nov 23, 2023 at 9:28
  • \$\begingroup\$ I meant photo, but that illustration adds insight also. What connectors do you use? \$\endgroup\$
    – MiNiMe
    Nov 23, 2023 at 9:32

2 Answers 2

3
\$\begingroup\$

It's not always a good idea to carry I²C signals with interconnections and wires/connections but if you can, use a 7-pin connector instead:

SDA GND SCL V+ SCL GND SDA

Another idea is as they are connected via GPIO, listen to one pin and detect, whether this one is the Clock or not.

This can be possible because the start condition is to pull SDA low whilst CLK is at idle. There's a delay before the CLK is pulled low. So you can detect this with your MCU having two falling-edge-triggered interrupt pins so you can reconfigure them.

This can be problematic, though, if your MCU's pin functionality (alternate function mapping) doesn't allow you to select SDA and SCL independently and freely. For STM8, for example, you can't randomly configure a pin for SDA, unless you write your own I²C module (e.g. bit banging).

\$\endgroup\$
4
  • \$\begingroup\$ How would you go about it, when there is no information about when an I2C communication might be initiated? because this would need to happen every time a sensor restarts (happens frequently) \$\endgroup\$ Nov 23, 2023 at 11:57
  • \$\begingroup\$ @jbachmann Not much detail about the system and possible scenarios are given so it's hard to give a proper answer. All I could to is to make some assumptions. If I'd design the whole system (i.e. master and all slave devices) I'd make sure all the nodes powers up at the same time. And during the first power up / init stage which covers enumeration and configuration, I'd pump messages from master so every other slave could re-configure themselves. To make this possible every node should have either bit-banged I²C implementation or internal digital SPST/SPDT switches for SDA/SCL routing. \$\endgroup\$ Nov 23, 2023 at 13:41
  • \$\begingroup\$ @jbachmann but if you want some flexibility/dynamics i.e. allowing attaching and removal of sensors at random times then this is a totally different story. every time a sensor restarts this requires storing the settings i.e. once the configuration is done during first power up / init stage the resultant settings (i.e. pin config and routing) should be stored for further use. As you can see, so much hassle for a small work. Instead, either use a 7-pin connector with a similar/same pinout in my answer, or ensure proper connection. \$\endgroup\$ Nov 23, 2023 at 13:44
  • \$\begingroup\$ I see, it is not trivial at all to detect, which cable is which just from SCL/SDA and unfortunately 7 pins don't fit. \$\endgroup\$ Nov 27, 2023 at 7:47
0
\$\begingroup\$

Detecting which cable is which just from SCL/SDA is a big pain, especially, when each sensor should be able to be connected, independently from all others. And unfortunately 7 pins don't fit our size limitations. But using a swapping GND and V+:

V+ SCL GND SDA V+

It is possible to detect, which V+ is actually connected and thus determine the orientation of the connector.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.