0

I have an ATtiny261 MCU. The pin diagram shows 2 digital out pins, PA1 and PB1. I've found a need for a 3rd output pin. From my (very) basic understanding of SPI, the clock is triggered on a rising or falling edge of a digital signal, so I started wondering whether I could use the PB2 pin as an output pin. I found an answer to the inverse question that seemed promising. That answer speaks to the efficiency and more robust timing a SCK pin provides in the SPI case but doesn't raise any red flags per se for my less demanding case of driving an LED (very slow speed). Another user reported success using the SCK pin to drive an LED. So I'm left wondering why wouldn't Microchip also label the SCK pin as a third digital output pin?

enter image description here

dvogel
  • 121
  • 5
  • 2
    Are we supposed to to assume that when you say "digital output" you are referring to "DO"? Because without reading the datasheet, I would guess DO means something else since usually every pin is a GPIO (general purpose I/O). – DKNguyen Mar 17 '22 at 02:03
  • 3
    And looking at the manual in Section "12.3.2 Alternate Functions of Port A", DO indeed does not mean digital output. It means "data output" and goes along with "DI", data input which belong to a different peripheral. – DKNguyen Mar 17 '22 at 02:08
  • Oh my. Thank you for catching my mistake! I think I saw "digital input" and maid a mental leap that I should not have. When you say that every pin is a GPIO, do you mean that I can set any pin to output using DDRA & DDRB? I got on this path figuring out which of those bits were valid to set to 1. – dvogel Mar 17 '22 at 02:16
  • 5
    Yes, virtually any pin except super special functionality pins such as the power pins, voltage reference pins, boot pins, and oscilator/clock pins (and often you can even set some of the later ones in the list to GPIO as well). You have to set the pin to it's proper mode for it to behave as GPIO. – DKNguyen Mar 17 '22 at 02:21
  • 2
    And possibly pins that go to SWD or JTAG interface. – user57037 Mar 17 '22 at 05:45

1 Answers1

1

General purpose IO pins are just that -general, so you can set it as output and control it.

The pin has several alternate functions, and they are all listes in parentheses. The pin (on AVR) automatically is turned into SPI clock when the SPI peripheral is enabled, so it is no longer a GPIO pin you can control as GPIO.

Justme
  • 127,425
  • 3
  • 97
  • 261