AVR IO Alternative Functions Priority

avrfunction

If in an AVR microcontroller there's at least two functions for example SPI, Analog Comp and GPIO pins in one 8bit PORT what's the priority of the functions?
for example: If SPI enable first, and then using DDRx trying to set one PIN which used from SPI as GPIO (such as input or output) what's the final function?

EDIT:
Can i setup in a port a multible functions? For example: i want to enable SPI and use the other pins normally as a GPIO pins. or, to enable UART and using other rest pins as GPIO.
How can i do that?

Best Answer

The "Alternate Port Functions" subsection of the "I/O-Ports" section of the datasheet describes exactly how each pin will behave given the peripherals enabled. In the case of SPI, only either MISO (master) or the other three pins (slave) are forced to a specific direction (input in both cases); the other pins can have their direction configured to either conform to SPI or not as required/desired.

Note that DDRx, PORTx, and PINx can always be read from and written to regardless of the current functions of the corresponding pins, even if such an action does not make sense given their configuration.