Using two or more SPI devices simultaneously with an Arduino

Discuss everything related to Arduino - Open-source electronic prototyping platform allowing to create interactive electronic objects.
abhimanyu
Posts: 94
Joined: Tue Oct 18, 2011 9:49 pm

Using two or more SPI devices simultaneously with an Arduino

Postby abhimanyu » Mon Dec 26, 2011 5:42 pm

If someone wants to use more than one SPI (Serial Peripheral Interface) device with an Arduino, here is the trick:
1.) The MISO, MOSI and SCK pins need to be shared to all the devices.
2.) The SS pin can be any digital pin as long as it is set as an OUTPUT. If you want to use the digital pins 7 and 8, then you may write:

Code: Select all

pinMode(7, OUTPUT);
pinMode(8, OUTPUT);

3.) Set all the SS pins to be HIGH (disable all devices).

Code: Select all

digitalWrite(7, HIGH);
digitalWrite(8, HIGH);

4.) Now, the initial setup is done. When you have to use a particular SPI device, just set its corresponding SS pin to be LOW; then do what you want to do with the device; then again set it HIGH so that other devices may communicate through SPI.

Return to “Arduino”

Who is online

Users browsing this forum: No registered users and 1 guest