Alternative functions.

Hi all, I'm new to these boards and new to the AVR world. I've been involved in electronics for somewhat of a long time but not really at the hardware level like this. I did a ton of programing for windows using the tag names provided to me by a machine hardware guy. I built many SCADA systems(software) that were used heavily by multiple corporations and decided to delve into the hardware part of it. Most things I get but I never have worked directly with AVRs.

Now for my question, I've been using the atmega328p(nano) and I've run out of digital pins, more specifically for the SPI bus, I've used all of the D-pins available and have all but 2 of the ADC pins available. After reading the data-sheet I'm a bit confused about the alternative modes of operation. The data-sheet says that all of the ADC pins can be used as interrupt pins, but doesn't say if they can be used as a digital pin for use on the SPI bus. All the current digital pins are being used for SPI except for 1 which I'm using as a switch. So is it possible to use the ADC pins I have available for SPI communication via the alternative pin functions?

Any help and or information would be greatly appreciated.

Thanks in advance.

Only one set of pins can be used for the three main SPI pins (the MISO/MOSI/SCK pins are fixed, as marked on any pinout diagram) - though any pin can be used as a slave select pin, or with a software SPI implementation.

All analog pins on all arduino-supported AVR micros can be used as digital pins except A6 and A7 on the 328(p). This is something very frustrating about the Arduino pin naming scheme, and it confuses a lot of people - the naming scheme implies that the analog are fundamentally different. They're not - they're just digital pins that have an extra functionality, just like how some digital pins can also do PWM, and some digital pins can also do SPI - in addition to being normal digital pins.

You can call pinMode() and digitalWrite() on the analog pins, either using the A# notation, or with the numbers (they start where the "digital pins" leave off - digitalWrite(A0,1) is the same as digitalWrite(14,1)

Thanks for the quick response. I was also just thinking, I do have a couple of I2C port expenders. Would this, maybe be a better way to go to add the additional SPI pins needed? I need to add a SD card to the system for data logging
And to my original question is that a yes or no? Sounds like a yes, I think. As I said I'm new to this aspect of hardware. Knowing the tags is way different then knowing the hardware underlying the tags.

Again, thanks for the quick response.

You don't need additional SPI pins - all devices connect to SCK, MOSI, MISO in parallel, and each gets its own unique slave select. If you run out of pins for slave selects, than some kind of expansion might be needed - but a shift register is all that is needed to create 8 more slave selects, or 16 if you daisy chain two. Port expander could be used.

CrossRoads:
You don't need additional SPI pins - all devices connect to SCK, MOSI, MISO in parallel, and each gets its own unique slave select. If you run out of pins for slave selects, than some kind of expansion might be needed - but a shift register is all that is needed to create 8 more slave selects, or 16 if you daisy chain two. Port expander could be used.

So what you're saying is, I could have multiple devices connected to D13, D12,D11 and use an unused pin as the cable select and it would still work since the cable select for a particular device decides who captures the signals. Is that right?

I'm still trying to wrap my head around this, been a long time since I was in school and kind of remember some things but not enough to know for sure.

Thanks in advance

Thanks a lot guys, you've been a great help in getting this straightened out in my head.

Thanks to all for the help!