I have the capability of installing multiple SPI devices on the backplane. Each configuration creates the possibility of conflicting assignments for the SPI chip selects. I can reserve 8 pins on the backplane, corresponding to Arduino Mega pins D42-49 (PL0-PL7), as well as the default D53 (PB0). That makes 9 pins on 2 ports available as chip selects for separate SPI devices. A device may have one chip select assignment for one configuration, but need to be reassigned for another. A device may share a driver with another SPI device. So if I edit the drivers to take a chip select at run time from my reserve pool, I can avoid conflicts. That is the reason for using the pointers *SSDDR and *SSPORT, because as SS changes, the DDR and PORT can change. The modified code for the assignment routine in TinyFAT below:
void mmc::setSSpin(const uint8_t _pin) {
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
if (_pin==53) {
SSPORT = &PORTB;
SSDDR = &DDRB;
SS=0;
}
else if ((_pin>=42) and (_pin<=49)) {
SSPORT = &PORTL;
SSDDR = &DDRL;
SS= 49 - _pin;
}
#else if ((_pin>=8) and (_pin<=10)) {
SS=_pin-8;
SSPORT = &PORTB;
SSDDR = &DDRB;
}
#endif
}
Anyhow, the backplane now appears to handle multiple SD cards without conflict, using the modified TinyFAT. Hopefully, drivers for other SPI devices can be similarly modified as needed.