Stop and start I2C to allow multi use of the pins.

There was another question along these lines...
stop i2c - Interfacing - Arduino Forum but no solution was offered.
The problem I have is similar to that one, but the folks that answered could not seem to understand.
They just seem to say, use more pins!

I have an old Codan 8525A HF radio and it bit bangs control signals to drive I2C, CBUS and shift resisters all on the same 2 pins.
As I do not want to mod the boards, just remove the 80C31 and EPROM, then plug an Arduino into a custom board that fits in place, I need to use I2C, CBUS (I've written the bit bang driver and it works), and shift register for the PLL chips, all on the Arduino A4 and A5 pins.
Yes, I know I could use different pins and cut the Codan board tracks, but I want to keep it original and have the mods reversible. Also, when I get it all going, it will be a simple add on change for others to use this great old transceiver on the HF ham bands.
So, back to the question!
If the I2C has been started, the A4 and A5 pins no longer respond to digitalWrite and digitalRead commands.
I need to be able to run the I2C stuff, then turn the I2C off, and use the pins as "normal". Then turn I2C back on when needed....

Any help would be appreciated.

I may just add an external analog MUX but that is a fix of a symptom, not the problem :slight_smile:

There is a wire.end() method that might be useful. It calls twi_disable().

Probably, you need external Mux Switch as depicted below to align the external I2C device and DIO device with the UNO's I2C Logic and DIO Logic respectively. The Wire.begin()/Wire.end() commands will control the K1/K2 switches of UNO; the PB0/PB1 lines will control the K3/K4 switches of Mux Switch.


I have the MUX added, but it is the other way around.
The Arduino has the SCL and SDA into one MUX port pair, a couple of pins for SClock and SData into another MUX port pair, the other 2 pairs are connected to +5V and gnd.
A pair of Arduino lines run the MUX selectors.

#define Sdata 8 // extra “SDA”
#define Sclock 7 // extra “SCL”
#define MUX0 9 // serial data and serial clock MUX0 control
#define MUX1 10 // serial data and serial clock MUX1 control

digitalWrite(MUX0,LOW); // 0 = I2C, 1 = Other, 2 = +5V, 3 = gnd.

I will try the other commands to see if they work.
Thanks for that info.

Hmmm. I could not figure out how to make the jpg visible.

1. You follow these steps to make your jpg picture visible online:
(1) Right Click on the saved file object and click on 'copy link address'.
(2) Open your post in Modify/Edit mode.
(3) Place the cursor where you want to insert your picture.
(4) click on the Insert an image icon of the tool bar of the post page.
(5) A small dialog window will appear and follow the menu.
(6) Press Cntrl+V to paste the link of your image.
(7) Click on OK button, save the post. Observe that your picture (Fig-1) is on the post.


2. What are these extra things:

#define Sdata           8    // extra "SDA"
#define Sclock          7    // extra "SCL"

3. I am posting below a picture (Fig-2, untested) showing the implementation of my picture of Post#3 using 4052.



It actually works!
I’ve added some LEDS on A4 andA5, as well as an I2C LCD. Here is my test code…

/* try to use A4 and A5 as other i/os as well s SDA and SCL…

#define Version"Share I2C pins"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

int counter=0;

LiquidCrystal_I2C lcd(0x3F,16,2);

void setup() {
lcd.init(); // initialize the lcd

void loop() {

counter++; // generate a count and display it on the I2C LCD.

Wire.end(); // stop the I2C and free up the pins for other use.

pinMode(A4,OUTPUT); // setup A4 and A5 as outputs

digitalWrite(A4,HIGH); // then flash some LEDS on A4 and A5

Wire.begin(); // start the I2C again to drive the I2C LCD interface

When A5 is HIGH and A4 drops to LOW, that is a I2C START condition.
With enough pulses, some day some chip might reply to its address and pull SDA low. When the Arduino has SDA HIGH at that moment, then you have a shortcut.

It is safer to keep the "open-collector" function for A4 and A5. Make the pin LOW or keep the pin floating (by making it INPUT).

I would set the A4 and A5 to INPUT before calling Wire.begin(), just for safety.

When you keep SDA as INPUT and floating (a pullup resistors should pull it high), then you can use the SCL pin for other things. No device on the I2C bus will do something, because there is never a START condition. Using SCL for other things that way is 100% safe.