Skip to content

Migrate & convert SPI docs from older platform #866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions Language/Functions/Communication/SPI.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
title: SPI
categories: [ "Functions" ]
subCategories: [ "Communication" ]
---


= SPI


// OVERVIEW SECTION STARTS
[#overview]
--

[float]
=== Description


This library allows you to communicate with SPI devices, with the Arduino as the controller device. This library is bundled with every Arduino platform (avr, megaavr, mbed, samd, sam, arc32), so *you do not need to install* the library separately.

To use this library

`#include <SPI.h>`

To read more about Arduino and SPI, you can visit the https://docs.arduino.cc/learn/communication/spi[Arduino & Serial Peripheral Interface (SPI)] guide.

--
// OVERVIEW SECTION ENDS


// FUNCTIONS SECTION STARTS
[#functions]
--

'''

[float]
=== Functions
link:../SPI/SPISettings[SPISettings] +
link:../SPI/begin[begin()] +
link:../SPI/beginTransaction[beginTransaction()] +
link:../SPI/end[end()] +
link:../SPI/setBitOrder[setBitOrder()] +
link:../SPI/setClockDivider[setClockDivider()] +
link:../SPI/setDataMode[setDataMode()] +
link:../SPI/transfer[transfer()] +
link:../SPI/usingInterrupt[usingInterrupt()]

'''

--
// SEEALSO SECTION ENDS
42 changes: 42 additions & 0 deletions Language/Functions/Communication/SPI/SPISettings.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: SPISettings
---

= SPISettings


// OVERVIEW SECTION STARTS
[#overview]
--

[float]
=== Description
The `SPISettings` object is used to configure the SPI port for your SPI device. All 3 parameters are combined to a single `SPISettings` object, which is given to `SPI.beginTransaction()`.

When all of your settings are constants, SPISettings should be used directly in `SPI.beginTransaction()`. See the syntax section below. For constants, this syntax results in smaller and faster code.

If any of your settings are variables, you may create a SPISettings object to hold the 3 settings. Then you can give the object name to SPI.beginTransaction(). Creating a named SPISettings object may be more efficient when your settings are not constants, especially if the maximum speed is a variable computed or configured, rather than a number you type directly into your sketch.

[float]
=== Syntax
`SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE0))`
Note: Best if all 3 settings are constants

`SPISettings mySettting(speedMaximum, dataOrder, dataMode)`
Note: Best when any setting is a variable''


[float]
=== Parameters
`speedMaximum`: The maximum speed of communication. For a SPI chip rated up to 20 MHz, use 20000000. +
`dataOrder`: MSBFIRST or LSBFIRST +
`dataMode`: SPI_MODE0, SPI_MODE1, SPI_MODE2, or SPI_MODE3


[float]
=== Returns
None.

--
// OVERVIEW SECTION ENDS

33 changes: 33 additions & 0 deletions Language/Functions/Communication/SPI/begin.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: SPI.begin()
---

= SPI.begin()


// OVERVIEW SECTION STARTS
[#overview]
--

[float]
=== Description
Initializes the SPI bus by setting SCK, MOSI, and SS to outputs, pulling SCK and MOSI low, and SS high.


[float]
=== Syntax
`SPI.begin()`


[float]
=== Parameters
None.


[float]
=== Returns
None.

--
// OVERVIEW SECTION ENDS

33 changes: 33 additions & 0 deletions Language/Functions/Communication/SPI/beginTransaction.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: SPI.beginTransaction()
---

= SPI.beginTransaction()


// OVERVIEW SECTION STARTS
[#overview]
--

[float]
=== Description
Initializes the SPI bus using the defined link:SPISettings[SPISettings].


[float]
=== Syntax
`SPI.beginTransaction(mySettings)`


[float]
=== Parameters
mySettings: the chosen settings according to link:SPISettings[SPISettings].


[float]
=== Returns
None.

--
// OVERVIEW SECTION ENDS

33 changes: 33 additions & 0 deletions Language/Functions/Communication/SPI/end.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: SPI.end()
---

= SPI.end()


// OVERVIEW SECTION STARTS
[#overview]
--

[float]
=== Description
Disables the SPI bus (leaving pin modes unchanged).


[float]
=== Syntax
`SPI.end()`


[float]
=== Parameters
None.


[float]
=== Returns
None.

--
// OVERVIEW SECTION ENDS

33 changes: 33 additions & 0 deletions Language/Functions/Communication/SPI/endTransaction.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: SPI.endTransaction()
---

= SPI.endTransaction()


// OVERVIEW SECTION STARTS
[#overview]
--

[float]
=== Description
Stop using the SPI bus. Normally this is called after de-asserting the chip select, to allow other libraries to use the SPI bus.


[float]
=== Syntax
`SPI.endTransaction()`


[float]
=== Parameters
None.


[float]
=== Returns
None.

--
// OVERVIEW SECTION ENDS

35 changes: 35 additions & 0 deletions Language/Functions/Communication/SPI/setBitOrder.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: SPI.setBitOrder()
---

= SPI.setBitOrder()


// OVERVIEW SECTION STARTS
[#overview]
--

[float]
=== Description
This function should not be used in new projects. Use link:SPISettings[SPISettings]. with link:beginTransaction[SPI.beginTransaction()]. to configure SPI parameters.

Sets the order of the bits shifted out of and into the SPI bus, either LSBFIRST (least-significant bit first) or MSBFIRST (most-significant bit first).


[float]
=== Syntax
`SPI.setBitOrder(order)`


[float]
=== Parameters
order: either LSBFIRST or MSBFIRST


[float]
=== Returns
None.

--
// OVERVIEW SECTION ENDS

47 changes: 47 additions & 0 deletions Language/Functions/Communication/SPI/setClockDivider.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
title: SPI.setClockDivider()
---

= SPI.setClockDivider()


// OVERVIEW SECTION STARTS
[#overview]
--

[float]
=== Description
This function should not be used in new projects. Use link:SPISettings[SPISettings]. with link:beginTransaction[SPI.beginTransaction()]. to configure SPI parameters.

Sets the SPI clock divider relative to the system clock. On AVR based boards, the dividers available are 2, 4, 8, 16, 32, 64 or 128. The default setting is SPI_CLOCK_DIV4, which sets the SPI clock to one-quarter the frequency of the system clock (4 Mhz for the boards at 16 MHz).

*For Arduino Due:* On the Due, the system clock can be divided by values from 1 to 255. The default value is 21, which sets the clock to 4 MHz like other Arduino boards.


[float]
=== Syntax
`SPI.setClockDivider(divider)`


[float]
=== Parameters

divider (only AVR boards):
* SPI_CLOCK_DIV2
* SPI_CLOCK_DIV4
* SPI_CLOCK_DIV8
* SPI_CLOCK_DIV16
* SPI_CLOCK_DIV32
* SPI_CLOCK_DIV64
* SPI_CLOCK_DIV128

chipSelectPin: peripheral device CS pin (Arduino Due only)
divider: a number from 1 to 255 (Arduino Due only)

[float]
=== Returns
None.

--
// OVERVIEW SECTION ENDS

41 changes: 41 additions & 0 deletions Language/Functions/Communication/SPI/setDataMode.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: SPI.setDataMode()
---

= SPI.setDataMode()

// OVERVIEW SECTION STARTS
[#overview]
--

[float]
=== Description
This function should not be used in new projects. Use link:SPISettings[SPISettings]. with link:beginTransaction[SPI.beginTransaction()]. to configure SPI parameters.

Sets the SPI data mode: that is, clock polarity and phase. See the Wikipedia article on http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus:[SPI] for details.

[float]
=== Syntax
`SPI.setDataMode(mode)`


[float]
=== Parameters

mode:

* SPI_MODE0
* SPI_MODE1
* SPI_MODE2
* SPI_MODE3


chipSelectPin - peripheral device CS pin (Arduino Due only)

[float]
=== Returns
None.

--
// OVERVIEW SECTION ENDS

40 changes: 40 additions & 0 deletions Language/Functions/Communication/SPI/transfer.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: SPI.transfer()
---

= SPI.transfer()

// OVERVIEW SECTION STARTS
[#overview]
--

[float]
=== Description

SPI transfer is based on a simultaneous send and receive: the received data is returned in receivedVal (or receivedVal16). In case of buffer transfers the received data is stored in the buffer in-place (the old data is replaced with the data received).

[float]
=== Syntax

`receivedVal = SPI.transfer(val)`

`receivedVal16 = SPI.transfer16(val16)`

`SPI.transfer(buffer, size)`


[float]
=== Parameters

* val: the byte to send out over the bus
* val16: the two bytes variable to send out over the bus
* buffer: the array of data to be transferred


[float]
=== Returns
The received data.

--
// OVERVIEW SECTION ENDS

Loading