1

I'm trying to connect an I2C OLED display and an n RF24L01 WiFi module to an ATTiny85. But I only need 1 extra pin. Is it possible to use the same clock wire/pin for the I2C and SPI device? Maybe with some extra code? Thanks a lot!

  • Do you have CS pin? Then yes, easily. When the SPI device is deselected, it doesn't care what you put on SCLK and the I2C will get it normally. The other way around, the I2C device doesn't have a CS and will listen to its address byte on the I2C SCL and SDA lines.. If SDA is seperate to the SPI bus, it will just read 0... and not do anything, even if there's a clock. – Maximilian Gerhardt Mar 4 at 16:44
  • Yes, in theory it is possible. You can use the scl for other things as long as you keep the sda high. The scl is a input clock for most i2c devices. I assume that the display itself does not pull the scl low. Changing between a open-collector and a digital ttl signal for the scl should therefor not be a problem. If the display has a microcontroller for i2c, then it might pull the scl low. Is the USI used for the i2c bus? Then there might be a shortcut when the SPI library keeps the scl high and the USI/I2C pulls it low. Can you share chipselect with scl? Then you can release the scl pin. – Jot Mar 4 at 16:45
  • @MaximilianGerhardt it is about the start condition for i2c. When sda does not turn low, there is no start condition and the i2c devices do nothing. – Jot Mar 4 at 16:47
  • @Jot oh right, you'd have to take that into account, too.. – Maximilian Gerhardt Mar 4 at 16:48
  • Perhaps it is safer to do Wire.begin, then normal i2c, then Wire.end() and the same for the spi. – Jot Mar 4 at 18:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.