# Configuring the Ports of an AVR Microcontroller for SPI Use

I am trying to configure the an ATtiny84A for use with SPI, but I have some confusion with what Is being said in the datasheet for configuring the ports. The ATtiny84A has, what the datasheet calls, "alternate port functions", so each port can have multiple functions. In my case with SPI, the pin that serves the SPI Clock also serves the ports GPIO functionality, an ADC, the clock for I2C, among others (as seen on page 64 of the datasheet: Port A, Bit 4).

What I understand from what its saying in the datasheet, is that it somehow automatically configures the port when a functionality is set. So what happens if I try to configure multiple of these port functions at a time? For example, what if I configure the ADC on port A4 and SPI which has its clock source on port A4? I can't find a table which explicitly states how to configure the port which enables or disables other functionalities, so I imagine that some sort of function priority is taken?

Furthermore, where is the information on setting the direction register to allow the SPI clock through? This confuses me, because like I said, the datasheet seems to say that the port is configured automatically; however, for me to pipe the clock through port A4, I must write a 1 to the direction register (set it as an output) for the clock source to come out, but I cannot find any information in the datasheet to back up this behaviour.

Here is some sample code for getting a continuous clock to come out of the SPI clock port:

USICR   |=  (1 << USIWM0);  // Set Bit 4 (USIWM0) of the USICR register
USICR   &=~ (1 << USIWM1);  // Clear Bit 5 (USIWM1) of the USICR register

USICR   &=~ (1 << USICS0);
USICR   |=  (1 << USICS1);
USICR   |=  (1 << USICLK);  //Sets USITC as the clock source for the 4 bit counter.

DDRA |= (1 << DDA4); // Configure PortA4 as an output?

while(1)
{
USICR |= (1 << USITC); // Toggle the SPI clock output.
}


EDIT: I'll summarize the information which I am specifically confused about/don't know what to do with from the datsheet:

Table 10-2, page 60: I am unsure what the purpose of these overriding signals are when configuring alternate port functions.

Table 10-5, page 64: I see the USI clock in this table, but I don't know what the rest of the information that it contains is telling me. I see that USCK is in the DI row, but I don't know what that is telling me for the configuration of the port.

• You may need to give the exact link to the data sheet you're referencing. There have been a number of revisions and there are a few different forms of each the data sheet. On the newest datasheet (from MicroChip.com) I don't see the items you're referencing
– Nedd
May 3 at 7:13
• @Nedd good point, it appears the data sheet I have is a different version. I’ll update the question with the page numbers and tables numbers from the data sheet currently listed on microchips page for the ATtiny84. May 3 at 7:20