Question: when using an AVR with multiple SPI ports,

Question: when using an AVR with multiple SPI ports, how will the library behave when controllers are assigned to those other SPI pins? Will it know to drive those other ports as SPIs or will it bitbang them?

Right now it bitbangs the other ones. What avrs have multiple hardware pins?

Some of the larger ones, though a lot of them (if not all of them) are actually USART ports that can be configured as master SPI (modes 0, 1, 2, and 3)

Ah - yeah, I haven’t finished USART SPI mode support.

Yet - definitely want to do that though.

But there is no harm in using them now with the current preview library. Once the code is in place, switching libraries shouldn’t cause any headaches, right? The next question will be figuring out whether to enable the SPI mode in the library, or let the user do that.

The goal for the library is to always use the best mechanism for whatever pins you’ve selected, whether it is hardware SPI, USART in SPI mode, or bitbanging (and even bitbanging, how it does the bitbanging changes based on whether or not the clock and data pins are on the same port :slight_smile:

Right, but one has to enable those pins to function as SPI by setting the appropriate bits. Is that something the library should do, or the user? Having the library doing it would also mean that it needs to figure out what AVR it’s on, whether the user is using those pins in the correct configuration, and whether the user actually wants to use those ports in SPI mode.

it’s something the library would do - and the library already does that - i have definitions for a variety of arduino variants for what pins the SPI hardware is on - it’d be the same thing with the USARTs.

I’m hard pressed to think of any reason that a user would rather bitbang than use the USART in SPI mode to push data out, other than not knowing that they could use the hardware. The hardware will always be anywhere from 2-20 times faster than bitbanging, and on some platforms, using hardware support opens up options for using DMA and background pushing of data.

SPI also requires setting a variety of register bits to turn on the hardware support.