0
\$\begingroup\$

I'm short on pins and am working with extremely low budget and small sized circuit board. So, if the I2C slave does not clock stretch, can I safely delegate the SCL pin to some output expander (Shift register or Binary Decoder)?

The circuit contains the following: ATtiny13a DS1307 74hc138 (binary decoder) or 74hc595 (shift register)

In short, is it absolutely necessary for the SCL line to be pulled up and kept in open drain condition? (Both in general and in context of DS1307 chip)

\$\endgroup\$
2
  • \$\begingroup\$ You can make any MCU signal open to drain using two transistors. Pull is a must as per protocol to detect proper start of messages. You have space for shift register or decoder? How are you connecting them to micro? \$\endgroup\$
    – User323693
    Commented Jun 13, 2018 at 4:49
  • \$\begingroup\$ @Umar I must have a decoder or a shift because I need to control several output leds. I was hoping that by moving the SCL to a pin expander, I could use the extra pin as an input. \$\endgroup\$
    – Nirav
    Commented Jun 13, 2018 at 16:06

2 Answers 2

4
\$\begingroup\$

Yes, for most simple slaves, master SCL can just be a push-pull output. If you feel like ensuring that a clock stretching slave did not draw too much current, you could have a series resistor.

BUT since SCL changes state 38 times to output a single byte to an I2C device, it really is the worst possible signal to put on a serial port expander.

You can share the I2C pins with other busses (see my page on that here), e.g SPI/74hc595 serial bus, or low speed uses like a status LED. So it is best to use a direct micro pin for the I2C, and share those pins with your other port expansion, or do the port expansion by I2C.

BTW, if you are only writing to an output device, then most hardware slaves can get by with SDA being an output only (since they will always respond), but it must have open drain, or a series resistor, as ACK will be pulled down by the slave.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks for answering. I read your page and I'm amazed I never thought to put both SPI and I2C on same line. I might have to rethink my circuit design now. \$\endgroup\$
    – Nirav
    Commented Jun 13, 2018 at 16:10
0
\$\begingroup\$

In general and in context of DS1307 chip you can use SCL line for other purposes as long as you do not change SDA line from high to low while SCL is high.

UPDATE:

The above was an answer to your direct question. And the answer is yes, you don't have to keep SCL high between transactions. That does not mean you should do it. In fact, the great benefit of I2C is that you can do a lot with same two lines without running out of pins.

For example I2C controlled PCA9548A switch can easily replace your 74HC138. You select an address (or any combination of them!) via I2C command, then pull SCL low and use SDA pin as general input/output. Only one chip and you already have 8 additional pins without using anything but same I2C pair.

There are similar solutions for SPI bus. ADG731 switch is controlled by SPI and can be used to multiplex CS line to as many as 32 other SPI devices. So, you only need 4 pins for all of them. There are even SPI-to-I2C converters that allow you to have both interfaces on same SPI pins without worrying about collisions.

I don't know what you are going to connect to your MCU but so far I was able to find just about everything I needed with one of these two interfaces.

\$\endgroup\$
3
  • \$\begingroup\$ Yes, but then when I am using I2C, the other circuit connected to SCL will also work, wont it? \$\endgroup\$
    – Nirav
    Commented Jun 13, 2018 at 16:12
  • \$\begingroup\$ Yes, of course. There is no magic here. If you do not change SDA while SCL is high the I2C device will not see "start" condition, so it will ignore clock pulses. But whatever else you connect to SCL will work on every pulse, even those you sending during I2C communication. \$\endgroup\$
    – Maple
    Commented Jun 13, 2018 at 16:39
  • \$\begingroup\$ @KittyHawk I've updated an answer to address your concern. \$\endgroup\$
    – Maple
    Commented Jun 13, 2018 at 18:22

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.