Multiple SPI chip select question

Thanks for the responses. I got it to work. If you are testing an SD interface, it can help to put an SD card in the slot. MarkT and johnwasser's suggestion about explicitly setting the default SS address as an output, even if it is not going to be used, is probably a good idea. I implemented it but my code had other problems. I have not tested it without the explicit assignment, so I can't say if it is critical. I guess you guys split a virtual pizza.

Apparently, to address the 8th bit, it is _BV(7), and not _BV(B10000000). Also, I had a "type" problem setting a variables to the PORTx pointers.

However, now the user can assign unique chip select addresses with a single call at run time. I have tested it out and I can access the SD with the SPI chip select set to any of the Mega pins numbers corresponding to Mega PORTL.

Yikes it's been 20 years since I had to untangle C indirect pointer addressing. Time for a beer.

// This does not work:

  uint8_t SSPORT = PORTL;
  uint8_t SSDDR =  DDRL;
  SSPORT |=  _BV(SS); // set SS
  SSDDR  |=  _BV(SS) ; // set SS as output

// But this does:

volatile uint8_t *SSPORT = &PORTL;
volatile uint8_t *SSDDR =  &DDRL;
*SSPORT |=  _BV(SS); // set SS
*SSDDR  |=  _BV(SS) ; // set SS as output