SPI "performance" with more than one device

Hello all !

My sketch uses nRF24L01, Ethernet shield with SD card on the SPI bus, each having it's own SS (4 SD, 10 Ethernet, 8 nRF24L01).
I use Arduino libraries ( SD, Ethernet) and Mirf library to drive these devices. Each is device is running fine, doing it's job....
BUT, since I added the nRF24L01 device, I noticed a slow down in my transferts from/to Ethernet and SD card...
Each operation takes twice the time it took before this module... I looked inside the Mirf library and seen the "SPI.setClockDivider(SPI_2XCLOCK_MASK);" line.

My question are :

  1. is it possible that this line cut SPI performance down to half ?
    2 is it possible to change this setting ?
  2. in case of negative answer to 2), is it possible to have a second SPI bus ?
  3. in case of positive answer to 3), how could I do ?

Is there another answer to my performance problem
Thanks for your answer
Pierre

  1. is it possible that this line cut SPI performance down to half ?

Yes, it's even quite probable that it cuts down even more. This is because

#define SPI_2XCLOCK_MASK 0x01  // SPI2X = bit 0 on SPSR

and the correct constant with the same value is

#define SPI_CLOCK_DIV16 0x01

So the SPI bus is running with 1MHz instead of 4MHz.

2 is it possible to change this setting ?

Yes, but not in the nRF24L01 library but you can change it back to the default value of SPI_CLOCK_DIV4 just before and call to the Ethernet or SD libraries. If you increase the speed in the nRF24L01 library you might get a too fast speed for the device and it won't operate anymore or be at least less reliable.

  1. in case of negative answer to 2), is it possible to have a second SPI bus ?

Not in hardware (on Arduinos).

  1. in case of positive answer to 3), how could I do ?

You could do it in software but this will be much slower, so this is probably no option for you.

Thanks :~

Just a question please, could I use :

  1. SPI.setClockDivider(slaveSelectPin_Ethernet, divider) for Ethernet/SD and,
  2. SPI.setClockDivider(slaveSelectPin_nRF24L01, divider) for nRF24L01 in my sketches
    and SPI library do the job ?

Thanks again
Pierre

You can't do that unless you are using a Due, but you can change the speed when accessing each SPI device. pylon told you how. Here is the code:

SPI.setClockDivider(SPI_CLOCK_DIV4);
// do nRF24 access here
SPI.setClockDivider(SPI_CLOCK_DIV2);

edit: Those may be a little fast. You might want to use SPI_CLOCK_DIV4 and SPI_CLOCK_DIV8.

Lot of thanks to all of you !
(I just forgot that my Arduino board was a 2560...)

I'll try this settings this evening !

Have a good day
Pierre

Again, thanks a lot !!!!

SPI.setClockDivider(SPI_CLOCK_DIV4);
.........
do want I want.... And everything came as it was before !!!!!!!!!!!!!!!
..........
SPI.setClockDivider(SPI_CLOCK_DIV16);

Mirf library is cutting SPI clock by 4... and everything using SPI bus is slowed seriously, but this module is so cheap and so easy to use !!!!!!!!!

Thanks !
Pierre