13
\$\begingroup\$

I'd like to know what "Alternative Function" refers to in the context of the IO ports of a microcontroller.

I don't need to know how to activate it when connecting to a peripherial, but I'd like to know what it exactly is and why we'd need it.

\$\endgroup\$
15
\$\begingroup\$

Many pins of your microcontroller have different functions. The 'normal' function would refer to GPIO, General Purpose Input/Output. In that case, you can use these pins directly by writing to and reading from the relevant registers.

'Alternate' functions would refer to other functions, that may include I2C, SPI, USART, CCP, PWM, Clock, ADC, etc... How you control the pins when in an alternate function depends on the peripheral, but it generally comes down to writing to and reading from special function registers (SFR); the peripheral takes care of the rest.

Which function is standard after a RESET depends (it is not always GPIO!), and you can find that in the relevant datasheet. Most of the time, you can select the function you want to use on-the-fly, so you can switch between peripherals.

By using one pin for several peripherals, you can make microcontrollers with very much features. However, because you most of the time want that peripheral on that pin all the time (and don't want to switch functions on-the-fly) you can't use all peripherals in one program, or at least not at the same time. On the other hand, that isn't really often needed anyway.


As Connor points out, 'alternate function' can refer to something else as well, in just a slightly different context: here it isn't about what function you put on a pin, but about what pin you use for a function. This is called Peripheral Pin Select, and basically means you can select which pin your peripheral is using. You could, for example, do RS232 over RA1 and RA2 or over RB1 and RB2.

See Connor's answer for a more detailed description (and upvote him for this).

\$\endgroup\$
5
\$\begingroup\$

In addition to @CamilStaps answer, there is another context where "alternate pin function" is a commonly used term.

Some microcontrollers have the option to switch their internal peripherals between several sets of IO lines. This way, you can avoid issues if you want to use internal modules (SPI, I2C, etc...) that have their functions mapped to the same set of pins.

There is generally a control-register that determines which set of pins the various peripherals are mapped to.


I know I've worked with a microcontroller that had this facility, but I'll be damned if I can remember the specific part-number.

Edit: Found it - It's available on many of the PIC24 and dsPIC parts: enter image description here

They call it "Peripheral Pin Select", but it's basically a mechanism for configuring the alternate pin functions.

\$\endgroup\$

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.