-1
\$\begingroup\$

I'm using an ATTINY20-XU that uses I2C to communicate with an RTC chip and I want to use SPI to program the microcontroller when it's on the board.

However, both the I2C and SPI peripherals share the same pins on the microcontroller. My question is if it's possible to use both protocols in this scenario. If so how?

\$\endgroup\$
5
  • \$\begingroup\$ At the same time? Or with an external multiplexer? \$\endgroup\$ Commented Sep 5 at 3:34
  • \$\begingroup\$ @TimWilliams At the same time \$\endgroup\$
    – MXVG
    Commented Sep 5 at 3:38
  • 1
    \$\begingroup\$ How would the peripherals sort out the signals? Or, how would you imagine the signals to appear in that case--? \$\endgroup\$ Commented Sep 5 at 3:51
  • 2
    \$\begingroup\$ @MXVG But you would not be using them at the same time. It is impossible for the MCU to execute code that communicates via I2C at the same time the MCU is being reprogrammed via SPI pins. You would be either running the program and using the pins for I2C, or, not executing the program and using the pins for in-system programming. \$\endgroup\$
    – Justme
    Commented Sep 5 at 4:07
  • 2
    \$\begingroup\$ Are you imagining loading a bootloader onto the chip? Regular in-circuit programming is a special mode with /RESET at 0V (or possibly 12v, depending). The MCU will not be running your code during that time. \$\endgroup\$ Commented Sep 5 at 4:54

2 Answers 2

4
\$\begingroup\$

This ATTINY is not capable of being programmed over SPI. You need TPI for this, which is a two-wire protocol.

Only TPIDATA and SDA are shared on PB1, SCK and TPICLK are not on the same pins.
This means you're fine.

During programming, RESET will set LOW. Putting the SCK pin in reset state.
There will be no clock edges present on the RTC chip.

\$\endgroup\$
1
\$\begingroup\$

The MCU would have configuration registers to select either SPI or I2C on the pins you want. You have to do that before you use the SPI driver. You wont be able to use SPI and I2C at the same time on same pins.

\$\endgroup\$

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.