1

I've noticed that when using the USI interface on the ATTiny to send I2C via the methods from "Wire.h" with the ATTiny Arduino implementation included from the library manager (ATTinyCore), while analogWrite PWM on PB4 (Arduino pin 4, physical pin 3) works OK, it seems attempting to use it on PB1 (Arduino pin 1, physical pin 6) behaves erratically or hangs the processor.

Is this expected behavior, and is there a workaround? With the SDA line on PWM pin 0, physical pin 5 if that's the case it means when using the hardware USI to do I2C communications, I'm down to a single hardware PWM output, which is kind of a bummer.

enter image description here

  • 1
    Just a suggestion (perhaps you have already done this), make sure you are using the most up to date support (software) for this processor. I had loads of problems with an ARM core Arduino until I updated the supporting software for that processor. – st2000 Jan 8 '18 at 13:20
  • @st2000 The version I have installed via the boards manager is 1.1.4, which is congruent with the latest release on the github page for the project as of August 2017, so likely no joy there. :( – Bitrex Jan 8 '18 at 13:31
  • The project also uses millis() which I believe does something with an interrupt on one of the two hardware timers, so I wonder if that might be part of the problem as well, though I was under the impression that firing a timer overflow interrupt wouldn't interfere with the PWM channels. I plan on breaking the situation down into bare-minimum sketches today to try and isolate the problem – Bitrex Jan 8 '18 at 13:35
2

This is normal.

Timer0 is used as the clock source for the USI. It's the only internal clock source that can be used. The only other option is to use "software polled" mode where it's up to the sketch (or support library) to manually create the clock signal (less than desirable) by setting a bit in a register at the right time.

So you can only use Timer1 for your own (PWM) purposes while using the USI.

  • In a situation where two Tiny devices were using i2c to communicate, and at least one of them required more than a single hardware PWM channel, would it be preferable to use software-polling on the slave and the USI on the master, or vice versa? – Bitrex Jan 8 '18 at 23:03
  • 1
    It only relates to master mode. In slave mode the clock is provided by the master, not Timer0. The slave can have all the PWM running. – Majenko Jan 8 '18 at 23:05
  • Ah, I didn't know if in acting as a slave it also required it for some purpose, that works out fine then. – Bitrex Jan 8 '18 at 23:10
  • 1
    The only time you need a timer both ends of a connection is for an asynchronous protocol like UART. – Majenko Jan 8 '18 at 23:15

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.