Using HI2C pins also as I/O ??

Hydroid

Senior Member
Hi All,

Hopefully not a dense question, but I can't seem to get my head around this...

I'm constructing a circuit using a 28X2 PICAXE and would like to use all eight Port C pins as inputs. The project also makes use of a DS1307 RTC, so C.3 and C.4 would be hooked up to the DS1307 hi2c scl and sda lines with the 4K7 ohm pullup resistors. But, if I also want to use C.3 and C.4 as inputs - to detect change of state of a microswitch (micro would feed 5V to the input pin when state changes), wouldn't the 4K7 ohm pullups always make C.3 and C.4 see a logical 'high' ??

Reason I'm asking is I know I saw a diagram somewhere on this forum, where someone's circuit was doing just that. They were using a different chip as I recall, but had a RTC hooked up and at the same time were also using those two lines as current sinks for two lines from a set of common anode 7-seg LEDs in a multiplexing arrangement - I'm still looking for that post, but it eludes me so far...

I've always kept the scl and sda lines dedicated to the RTC in previous circuits, but is it indeed possible to use them for RTC and I/O at the same time ?

Regards, John.
 

PaulRB

Senior Member
Yes, the pulldown resistors would make the pins read normally high, but you could connect your microswitch from the pins to 0V, so they would read low when the switches were activated. Problem would come if the switches were activated while the picaxe was communicating with the rtc, especially if using hi2cout at that moment - corrupt data would be sent, and there is no error detection AFAIK.

Paul
 

westaust55

Moderator
There is the HI2CSETUP OFF command should you which to disable the i2c comms while monitoring the switches. The OFF parameter reverts the pins back to normal behaviour by switching off the dedicated i2c module.

As has been mentioned previously, using switches on these lines while slave i2c devices are connected even with the i2c comms disabled/off may cause inadvertent interaction with the slave i2c devices with erroneous data.
 

Technical

Technical Support
Staff member
Can you not use two (or more) switches on a single pin (using it as an analogue input), that would give you the input count you need but leaving the i2c dedicated.
 

Hydroid

Senior Member
Hi,

Thanks for the replies. I managed to find the thread 'm talking about:

http://www.picaxeforum.co.uk/showthread.php?16020-20X2-4-digit-7-segment-Countdown-timer

In post one's attached diagram, he's using the i2c lines as sinks or the 'f' and 'dp' segments of the four common anode multiplexed 7-seg displays. So what has me confused is why is it that when either the 'f' or 'dp' lines are sinking current to turn on the respective segments, the i2c still functions as the line(s) would be pulled low... Or is it that since it's a multiplexed circuit, the line(s) is low only during the display time and then released so the i2c lines would function normally during communication.. Obviously, it must work as he's posted it in the finished projects section and I'm sure it must function OK.

In my case, it's not at matter of not having enough inputs (I still have a few port A's left on my 28X2), I'm just trying to understand using i2c lines as i/o as well... I guess, from your replies and further reading, that it's possible to do with the right circumstances, but probably better to leave them dedicated to i2c if other pins are available as i/o...

Regards, John.
 

nick12ab

Senior Member
Thanks for the replies. I managed to find the thread 'm talking about:

http://www.picaxeforum.co.uk/showthread.php?16020-20X2-4-digit-7-segment-Countdown-timer

In post one's attached diagram, he's using the i2c lines as sinks or the 'f' and 'dp' segments of the four common anode multiplexed 7-seg displays. So what has me confused is why is it that when either the 'f' or 'dp' lines are sinking current to turn on the respective segments, the i2c still functions as the line(s) would be pulled low... Or is it that since it's a multiplexed circuit, the line(s) is low only during the display time and then released so the i2c lines would function normally during communication.. Obviously, it must work as he's posted it in the finished projects section and I'm sure it must function OK.
He isn't using any i2c devices on those pins anyway so they can safely be used as normal I/O.
 

hippy

Ex-Staff (retired)
Note there's a difference in using I2C lines for output and as input. When output you can control things so they can be outputs and co-exist with I2C devices and I2C comms if careful, but with inputs that's not easily possible.

It might be possible to put largish pull-downs on each I2C bus line which do not affect I2C comms, put a switch+R in parallel with each I2C pull-up and detect the slight change in voltage when switch is pushed if the two I2C pins can read analogue.
 
Top