Reference.SPI History

Hide minor edits - Show changes to markup

November 21, 2012, at 12:55 PM by Federico -
Changed line 52 from:
Uno or Duemilanove13 or ICSP-411 or ICSP-112 or ICSP-310-
to:
Uno or Duemilanove11 or ICSP-412 or ICSP-113 or ICSP-310-
October 22, 2012, at 06:22 PM by Federico -
Changed lines 72-73 from:

Arduino Due has three exposed pins for the devices Slave Select (SS) lines (pins 4, 10, and 52). Pin 78 is an SS pin connected to the on-board external data flash memory, used to store variables while the board is powered off.

to:

Arduino Due has three exposed pins for the devices Slave Select (SS) lines (pins 4, 10, and 52).

September 24, 2012, at 12:46 PM by Federico -
Changed lines 34-38 from:
000
101
210
311
to:
SPI_MODE000
SPI_MODE101
SPI_MODE210
SPI_MODE311
September 17, 2012, at 03:27 PM by Federico -
Added lines 76-77:
Deleted lines 97-100:
September 17, 2012, at 02:40 PM by Cristian -Vacuum- Maglie -
Changed lines 70-71 from:
  • automatic handling of different device configurations (clock speed, data mode, etc) so every device can have its own configuration that is automatically selected.
to:
  • automatic handling of different device configurations (clock speed, data mode, etc) so every device can have its own configuration automatically selected.
September 17, 2012, at 02:37 PM by Cristian -Vacuum- Maglie -
Changed lines 19-20 from:
  • SS (Slave Select) - the pin on each device that the master can use to enable and disable specific devices. When a device's Slave Select pin is low, it communicates with the master. When it's high, it ignores the master. This allows you to have multiple SPI devices sharing the same MISO, MOSI, and CLK lines.
to:
  • SS (Slave Select) - the pin on each device that the master can use to enable and disable specific devices.

When a device's Slave Select pin is low, it communicates with the master. When it's high, it ignores the master. This allows you to have multiple SPI devices sharing the same MISO, MOSI, and CLK lines.

September 17, 2012, at 02:37 PM by Cristian -Vacuum- Maglie -
Changed lines 13-18 from:

With an SPI connection there is always one master device (usually a microcontroller) which controls the peripheral devices. Typically there are three lines common to all the devices,

  • Master In Slave Out (MISO) - The Slave line for sending data to the master,
  • Master Out Slave In (MOSI) - The Master line for sending data to the peripherals,
  • Serial Clock (SCK) - The clock pulses which synchronize data transmission generated by the master, and
  • Slave Select pin - the pin on each device that the master can use to enable and disable specific devices. When a device's Slave Select pin is low, it communicates with the master. When it's high, it ignores the master. This allows you to have multiple SPI devices sharing the same MISO, MOSI, and CLK lines.
to:

With an SPI connection there is always one master device (usually a microcontroller) which controls the peripheral devices. Typically there are three lines common to all the devices:

  • MISO (Master In Slave Out) - The Slave line for sending data to the master,
  • MOSI (Master Out Slave In) - The Master line for sending data to the peripherals,
  • SCK (Serial Clock) - The clock pulses which synchronize data transmission generated by the master

and one line specific for every device:

  • SS (Slave Select) - the pin on each device that the master can use to enable and disable specific devices. When a device's Slave Select pin is low, it communicates with the master. When it's high, it ignores the master. This allows you to have multiple SPI devices sharing the same MISO, MOSI, and CLK lines.
Changed lines 22-29 from:
  • Is data shifted in Most Significant Bit (MSB) or Least Significant Bit (LSB) first? This is controlled by the SPI.setBitOrder() function.
  • Is the data clock idle when high or low?
  • Are samples on the rising or falling edge of clock pulses? This and the clock idling are controlled by the SPI.setDataMode() function
  • What speed is the SPI running at? This is controlled by the SPI.setClockDivider() function.

The SPI standard is loose and each device implements it a little differently. This means you have to pay special attention to the device's datasheet when writing your code. Generally speaking, there are four modes of transmission. These modes control whether data is shifted in and out on the rising or falling edge of the data clock signal (called the clock phase, and whether the clock is idle when high or low (called the clock polarity). The four modes combine polarity and phase. The SPI.setClockDivider() allows you to change the clock speed (default is 4MHz), and the SPI.setDataMode() function lets you set the mode to control clock polarity and phase according to this table:

to:
  • Is data shifted in Most Significant Bit (MSB) or Least Significant Bit (LSB) first? This is controlled by the SPI.setBitOrder() function.
  • Is the data clock idle when high or low? Are samples on the rising or falling edge of clock pulses? These modes are controlled by the SPI.setDataMode() function.
  • What speed is the SPI running at? This is controlled by the SPI.setClockDivider() function.

The SPI standard is loose and each device implements it a little differently. This means you have to pay special attention to the device's datasheet when writing your code.

Generally speaking, there are four modes of transmission. These modes control whether data is shifted in and out on the rising or falling edge of the data clock signal (called the clock phase), and whether the clock is idle when high or low (called the clock polarity). The four modes combine polarity and phase according to this table:

Changed lines 37-38 from:

Once you have your SPI parameters set correctly you just need to figure which registers in your device control which functions, and you're good to go. This will be explained in the data sheet for your device.

to:

The SPI.setDataMode() function lets you set the mode to control clock polarity and phase.

Every SPI device has a maximum allowed speed for SPI Bus. The SPI.setClockDivider() allows you to change the clock speed to make your device working properly (default is 4MHz).

Once you have your SPI parameters set correctly you just need to figure which registers in your device control which functions, and you're good to go. This will be explained in the data sheet for your device.

Changed lines 49-56 from:
 MOSIMISOSCKSS
Uno / Duemilanove13 - ICSP-411 - ICSP-112 - ICSP-310
Mega1280 - Mega256051 - ICSP-450 - ICSP-152 - ICSP-353
LeonardoICSP-4ICSP-1ICSP-3-
DueICSP-4ICSP-1ICSP-34, 10, 52

MISO, MOSI, and SCK are also available in a consistent physical location on the ICSP header; this is useful, for example, in designing a shield that works on the Uno and the Mega.

to:
Arduino BoardMOSIMISOSCKSS (slave)SS (master)
Uno or Duemilanove13 or ICSP-411 or ICSP-112 or ICSP-310-
Mega1280 or Mega256051 or ICSP-450 or ICSP-152 or ICSP-353-
LeonardoICSP-4ICSP-1ICSP-3--
DueICSP-4ICSP-1ICSP-3-4, 10, 52

Note that MISO, MOSI, and SCK are available in a consistent physical location on the ICSP header; this is useful, for example, in designing a shield that works on every board.

Changed lines 59-78 from:
to:

Note about Slave Select (SS) pin on AVR based boards

All AVR based boards have an SS pin that is useful when they act as a slave controlled by an external master. Since this library supports only master mode, this pin should be set always as OUTPUT otherwise the SPI interface could be put automatically into slave mode by hardware, rendering the library inoperative.

It is, however, possible to use any pin as the Slave Select (SS) for the devices. For example, the Arduino Ethernet shield uses pin 4 to control the SPI connection to the on-board SD card, and pin 10 to control the connection to the Ethernet controller.

Added lines 65-82:

The Arduino Due's SPI interface works differently than any other Arduino boards. The library can be used on the Due with the same methods available to other Arduino boards or using the extended methods. The extended methods exploits the the SAM3X hardware and allows some interesting features like:

  • automatic handling of the device slave selection.
  • automatic handling of different device configurations (clock speed, data mode, etc) so every device can have its own configuration that is automatically selected.

Arduino Due has three exposed pins for the devices Slave Select (SS) lines (pins 4, 10, and 52). Pin 78 is an SS pin connected to the on-board external data flash memory, used to store variables while the board is powered off.

Due Extended SPI usage

Functions

Added lines 94-97:
September 12, 2012, at 12:39 AM by Scott Fitzgerald -
Changed lines 25-27 from:

The SPI standard is loose and each device implements it a little differently. This means you have to pay special attention to the device's datasheet when writing your code. Generally speaking, there are four modes of transmission. These modes control whether data is shifted in and out on the rising or falling edge of the data clock signal (called the clock phase, and whether the clock is idle when high or low (called the clock polarity). The four modes combine polarity and phase. The SPI.setDataMode() function lets you set the mode to control clock polarity and phase according to this table:

to:

The SPI standard is loose and each device implements it a little differently. This means you have to pay special attention to the device's datasheet when writing your code. Generally speaking, there are four modes of transmission. These modes control whether data is shifted in and out on the rising or falling edge of the data clock signal (called the clock phase, and whether the clock is idle when high or low (called the clock polarity). The four modes combine polarity and phase. The SPI.setClockDivider() allows you to change the clock speed (default is 4MHz), and the SPI.setDataMode() function lets you set the mode to control clock polarity and phase according to this table:

September 11, 2012, at 07:34 PM by Scott Fitzgerald -
Changed lines 56-57 from:

The Arduino Due's SPI interface works differently than other Arduino boards. It has three exposed pins for the Slave Select (SS) line (pins 4, 10, and 52). Pin 78 is an SS pin connected to the onboard external data flash, used to store variables while the board is powered off. The available SS pins for user's purpose are three and are listed in the table above.

to:

The Arduino Due's SPI interface works differently than other Arduino boards. It has three exposed pins for the Slave Select (SS) line (pins 4, 10, and 52). Pin 78 is an SS pin connected to the onboard external data flash, used to store variables while the board is powered off.

September 11, 2012, at 07:33 PM by Scott Fitzgerald -
Changed lines 56-59 from:

The Arduino Due differently to the other Arduino boards provides only four pins for the Slave Select (SS) line, and one of them (pin 78) is connected to the onboard external data flash, used to store user's variables while the board is powered off. The available SS pins for user's purpose are three and are listed in the table above.

With the Due the SPI library can be used in two different ways, with the standard methods shared with the other Arduino boards based on AVR microcontrollers, or in the extended mode, that extend the standard methods, that consists in using the feature of the microcontroller (SAM3X) that automatically handle the slave selection between multiple devices sharing the SPI bus (each device can have also different configurations such as clock speed and datamode).

to:

The Arduino Due's SPI interface works differently than other Arduino boards. It has three exposed pins for the Slave Select (SS) line (pins 4, 10, and 52). Pin 78 is an SS pin connected to the onboard external data flash, used to store variables while the board is powered off. The available SS pins for user's purpose are three and are listed in the table above.

The SPI library can be used on the Due with the standard methods available to other Arduino boards based on AVR microcontrollers, or in the extended mode. This mode extends the standard methods, by using the features of the SAM3X microcontroller. This enables automatic handling of the slave selection between multiple devices sharing the SPI bus (each device can have also different configurations such as clock speed and datamode).

August 29, 2012, at 01:12 PM by Federico -
Changed lines 25-27 from:

The SPI standard is loose and each device implements it a little differently. This means you have to pay special attention to the device's datasheet when writing your code. Generally speaking, there are three modes of transmission. These modes control whether data is shifted in and out on the rising or falling edge of the data clock signal (called the clock phase, and whether the clock is idle when high or low (called the clock polarity). The three modes combine polarity and phase. The SPI.setDataMode() function lets you set the mode to control clock polarity and phase according to this table:

to:

The SPI standard is loose and each device implements it a little differently. This means you have to pay special attention to the device's datasheet when writing your code. Generally speaking, there are four modes of transmission. These modes control whether data is shifted in and out on the rising or falling edge of the data clock signal (called the clock phase, and whether the clock is idle when high or low (called the clock polarity). The four modes combine polarity and phase. The SPI.setDataMode() function lets you set the mode to control clock polarity and phase according to this table:

Changed lines 44-48 from:
Uno / Duemilanove13111210
Mega1280 / Mega256051505253
LeonardoICSPICSPICSPICSP
DueICSPICSPICSP4, 10, 52
to:
Uno / Duemilanove13 - ICSP-411 - ICSP-112 - ICSP-310
Mega1280 - Mega256051 - ICSP-450 - ICSP-152 - ICSP-353
LeonardoICSP-4ICSP-1ICSP-3-
DueICSP-4ICSP-1ICSP-34, 10, 52
Added lines 51-52:
August 28, 2012, at 06:00 PM by Federico -
Changed lines 51-52 from:

Note that even if you're not using the SS pin, it must remain set as an output; otherwise, the SPI interface can be put into slave mode, rendering the library inoperative. It is, however, possible to use a pin other than pin 10 as the slave select (SS) pin. For example, the Arduino Ethernet shield uses pin 4 to control the SPI connection to the on-board SD card, and pin 10 to control the connection to the Ethernet controller. Differently to the other boards the Due provides only 4 pins for the Slave Select line, and one of them (pin 78) is connected to the onboard external data flash, used to store user's variables while the board is powered off.

to:

Note that even if you're not using the SS pin, it must remain set as an output; otherwise, the SPI interface can be put into slave mode, rendering the library inoperative. It is, however, possible to use a pin other than pin 10 as the slave select (SS) pin. For example, the Arduino Ethernet shield uses pin 4 to control the SPI connection to the on-board SD card, and pin 10 to control the connection to the Ethernet controller.

Due Differences

The Arduino Due differently to the other Arduino boards provides only four pins for the Slave Select (SS) line, and one of them (pin 78) is connected to the onboard external data flash, used to store user's variables while the board is powered off. The available SS pins for user's purpose are three and are listed in the table above.

With the Due the SPI library can be used in two different ways, with the standard methods shared with the other Arduino boards based on AVR microcontrollers, or in the extended mode, that extend the standard methods, that consists in using the feature of the microcontroller (SAM3X) that automatically handle the slave selection between multiple devices sharing the SPI bus (each device can have also different configurations such as clock speed and datamode).

August 28, 2012, at 05:27 PM by Federico -
Changed lines 28-34 from:
ModeClock Polarity (CPOL)Clock Phase (CPHA)
000
101
210
311
to:
ModeClock Polarity (CPOL)Clock Phase (CPHA)
000
101
210
311
Changed lines 40-43 from:

On the Arduino Duemilanove and other ATmega168 / 328-based boards, the SPI bus uses pins 10 (SS), 11 (MOSI), 12 (MISO), and 13 (SCK). On the Arduino Mega, this is 50 (MISO), 51 (MOSI), 52 (SCK), and 53 (SS). MISO, MOSI, and SCK are also available in a consistent physical location on the ICSP header; this is useful, for example, in designing a shield that works on the Uno and the Mega.

Note that even if you're not using the SS pin, it must remain set as an output; otherwise, the SPI interface can be put into slave mode, rendering the library inoperative. It is, however, possible to use a pin other than pin 10 as the slave select (SS) pin. For example, the Arduino Ethernet shield uses pin 4 to control the SPI connection to the on-board SD card, and pin 10 to control the connection to the Ethernet controller.

to:

The following table display on which pins the SPI lines are broken out on the different Arduino boards:

 MOSIMISOSCKSS
Uno / Duemilanove13111210
Mega1280 / Mega256051505253
LeonardoICSPICSPICSPICSP
DueICSPICSPICSP4, 10, 52

MISO, MOSI, and SCK are also available in a consistent physical location on the ICSP header; this is useful, for example, in designing a shield that works on the Uno and the Mega.

Note that even if you're not using the SS pin, it must remain set as an output; otherwise, the SPI interface can be put into slave mode, rendering the library inoperative. It is, however, possible to use a pin other than pin 10 as the slave select (SS) pin. For example, the Arduino Ethernet shield uses pin 4 to control the SPI connection to the on-board SD card, and pin 10 to control the connection to the Ethernet controller. Differently to the other boards the Due provides only 4 pins for the Slave Select line, and one of them (pin 78) is connected to the onboard external data flash, used to store user's variables while the board is powered off.

Changed lines 78-79 from:
to:
August 26, 2012, at 02:10 AM by Scott Fitzgerald -
Added lines 57-59:

Extended SPI functionality for the Due

June 29, 2012, at 05:04 AM by David A. Mellis -
Changed lines 40-43 from:

On the Arduino Duemilanove and other ATmega168 / 328-based boards, the SPI bus uses pins 10 (SS), 11 (MOSI), 12 (MISO), and 13 (SCK). On the Arduino Mega, this is 50 (MISO), 51 (MOSI), 52 (SCK), and 53 (SS). Note that even if you're not using the SS pin, it must remain set as an output; otherwise, the SPI interface can be put into slave mode, rendering the library inoperative.

It is possible to use a pin other than pin 10 as the slave select (SS) pin. For example, the Arduino Ethernet shield uses pin 4 to control the SPI connection to the on-board SD card, and pin 10 to control the connection to the Ethernet controller.

to:

On the Arduino Duemilanove and other ATmega168 / 328-based boards, the SPI bus uses pins 10 (SS), 11 (MOSI), 12 (MISO), and 13 (SCK). On the Arduino Mega, this is 50 (MISO), 51 (MOSI), 52 (SCK), and 53 (SS). MISO, MOSI, and SCK are also available in a consistent physical location on the ICSP header; this is useful, for example, in designing a shield that works on the Uno and the Mega.

Note that even if you're not using the SS pin, it must remain set as an output; otherwise, the SPI interface can be put into slave mode, rendering the library inoperative. It is, however, possible to use a pin other than pin 10 as the slave select (SS) pin. For example, the Arduino Ethernet shield uses pin 4 to control the SPI connection to the on-board SD card, and pin 10 to control the connection to the Ethernet controller.

December 16, 2010, at 04:08 AM by David A. Mellis -
Changed lines 63-64 from:
to:
November 21, 2010, at 07:44 PM by David A. Mellis -
Changed lines 28-29 from:
ModeClock Polarity (CPOL)Clock Phase (CPHA)'''
to:
ModeClock Polarity (CPOL)Clock Phase (CPHA)
November 21, 2010, at 07:43 PM by David A. Mellis -
Changed lines 3-6 from:
to:
Deleted lines 8-17:
Changed lines 28-48 from:
to:
ModeClock Polarity (CPOL)Clock Phase (CPHA)'''
000
101
210
311
Changed lines 44-56 from:
to:
Deleted line 61:
Added lines 64-66:
August 15, 2010, at 03:45 PM by Tom Igoe -
Added lines 1-73:

Share