Multi use for Arduino I2C pins?

Thread Starter

dendad

Joined Feb 20, 2016
4,639
I have a CODAN 8525A radio that I am setting up for HAM use.
It has a CLK and DATA bus shared between I2C (4 x PCF8574, 1 x PCF8570), CBUS (2xSAA1061) and the bit banged 2 x MC145159 PLLs.
This is not counting the remote display that I will not use.
My problem is I can read the PCF8574 chips using I2C, or write to the SAA1061 chips via bit banged code, and "sort off" drive the PLLs, if I can figure out the maths to calculate the numbers!
BUT, if I use any Arduino Wire commands, as in the I2C, the SDA (A4) and SCL (A5) pins are not available for other use. The bit bang code still runs, but the SDA and SCL pins do not toggle.
I can cut tracks and use other Arduino pins, but I just want to keep the board standard, remove the 80C31 and EPROM, and plug an Arduino board in their sockets. This lets me use the original setup, and also, makes it an easy upgrade for those with one of these sets.
So far I have not been able to find any programming info or Ham band EPROM bin files to use it as original. And the circuits I've got are not quite this set. Most info refers to 8528 sets or later.
Anyhow, does any one know how to switch A4 and A5 between digital I/O, I2C (SDA, SCL) and back again on the Arduino?

Codan8525A.jpg
Codan8525A  btm.jpg
Codan8525A PLLs.jpg
Codan8525A ProcessorCard.jpg
 

Thread Starter

dendad

Joined Feb 20, 2016
4,639
There was another person's question https://forum.arduino.cc/index.php?topic=15992.0 in 2010, but they did not get any real answers, just advice to use multiple pins.
I have posted on the Arduino forum too, and it will be interesting to see if any answers result.
For developing the app, I think I'll add an external MUX so I can use a pair of i/o pins to get it going, but I would prefer to not have to add that.
 

Thread Starter

dendad

Joined Feb 20, 2016
4,639
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.
digitalWrite(MUX1,LOW);
I2C_MUX.jpg
This works.
 

mckenney

Joined Nov 10, 2018
125
There was another person's question https://forum.arduino.cc/index.php?topic=15992.0 in 2010, but they did not get any real answers, just advice to use multiple pins.
I see a pair of functions in twi.c (hardware/arduino/avr/libraries/Wire/src/utility) twi_init and twi_disable, which respectively set/clear TWCR:TWEN. These are called by TwoWire::begin and ::end. Clearing TWEN releases the pins to GPIO function.

That said: Doing that doesn't remove the other devices from the (shared) bus. If you start wiggling those wires, I would expect that the other devices will notice. (I think that was the essence of the discussion you referenced over at arduino.cc, but I'm not sure anyone came out and said it that way.)
 

Thread Starter

dendad

Joined Feb 20, 2016
4,639
If you mean TwoWire.end(); it does not compile.
I must be doing something wrong. I've tries various forms of this.

How do I write it?
 

Thread Starter

dendad

Joined Feb 20, 2016
4,639
For example......

#include "Wire.h"
#include <LiquidCrystal_I2C.h>
.
LiquidCrystal_I2C lcd(0x27,20,4);
.
lcd.init();

Is what I use here. I cannot turn that off.

lcd.end(); or LiquidCrystal_I2C.end(); do not work.

I even tried writing...
void TWI_on()
{
TWCR = TWCR | B00000101;
}

void TWI_off()
{
TWCR = TWCR & B11111010;
}

It looks like the MUX will be it for now.
 

djsfantasi

Joined Apr 11, 2010
9,237
Sometimes the order in which initialization of your I2C objects affects operations. When my laptop battery recharges enough to start (another story), I’ll pull up a previous project which used three I2C shields on an Arduino.

I had to run many tests initializing the shields in different orders. I was eventually get everyone to play together happily.

My point is there are many factors when using multiple I2C peripherals.
 

Thread Starter

dendad

Joined Feb 20, 2016
4,639
Sometimes the order in which initialization of your I2C objects affects operations. When my laptop battery recharges enough to start (another story), I’ll pull up a previous project which used three I2C shields on an Arduino.

I had to run many tests initializing the shields in different orders. I was eventually get everyone to play together happily.

My point is there are many factors when using multiple I2C peripherals.
Yes, that is so. But, my problem is I need to drive I2C and SBUS and a 64bit shift reg on the same line. They are not all I2C. And, when the I2C is enabled, the A4 and A5 pins no longer respond to digitalWrite commands. There is no trouble using I2C, just with turning it off again so the pins are available.
 
Top