Using SdFat library with other SPI devices

I am considering using an SD card and another SPI slave device (an atmega328p as SPI slave) on SPI bus. I have some concerns with setting the bus speed divider. Some code for using one arduino as SPI master starts with SPI.begin() and some has setClockDivider() (was default value 4MHz?):

http://tronixstuff.com/2011/05/13/tutorial-arduino-and-the-spi-bus/

I know that one can effectively set bus clock divider with:

sd.begin(SD_card_chip_select, SPI_HALF_SPEED)

The code is complicated within the begin method but I think they map SPI_FULL_SPEED to 8MHz and SPI_HALF_SPEED to 4MHz, right?

Then the SdFat library will not change the speed in later calls such read and write, right? So if I first begin the sd object as above, then I can just enable the other SPI slave with SS, and then write to it, cause the bus is already initialized by the sd.begin, and the speed stays at whatever I gave for sd.begin(), no need to set it again for the other slave, correct? Thanks.

Don't worry about SdFat. SdFat fully initializes the SPI bus before every use.

You do need to worry about other devices sharing the SPI bus. You must make sure the required mode, speed, and bit order are set before each device uses the SPI bus. Many libraries now handle this automatically in the same way as SdFat.

Thanks!

So according to the SdFat library (sd2card.cpp):

  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);

This means if I set up the master arduino by running sd.begin(CS, SPI_HALF_SPEED) and set up slave Arduino with these settings, I can talk with it, right? Maybe I should do the setup every time before sending to the slave arduino.

I saw that in order to get a byte from slave, the master sends out 0XFF, right? I saw this on a sparkfun tutorial as well. What I am trying to do is to do an async over SPI, like a fast “serial” port. Is this possible, with master polling slave all the time?

Don't worry what SdFat is doing. SPI setup occurs in SdFat several places.

Just make sure you set the SPI settings each time you send to the slave.

Got it. Thanks.

One more question on SPI: If I am running the bus at high speed, say 4MHz, then the received data on the slave side would be too fast for the slave to handle, right? I am considering ring buffer on an interrupt routine (not sure how to attach interrupt) in the slave unit to receive bytes. I may have to drop to a much lower rate to accommodate slave side interrupt handle's speed, correct?