Skip to content

Commit a6035d7

Browse files
committed
Migrate & convert SPI docs from older platform
1 parent 4ca291e commit a6035d7

11 files changed

+422
-0
lines changed
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
title: SPI
3+
categories: [ "Functions" ]
4+
subCategories: [ "Communication" ]
5+
---
6+
7+
8+
= SPI
9+
10+
11+
// OVERVIEW SECTION STARTS
12+
[#overview]
13+
--
14+
15+
[float]
16+
=== Description
17+
18+
19+
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.
20+
21+
To use this library
22+
23+
`#include <SPI.h>`
24+
25+
To read more about Arduino and SPI, you can visit the https://docs.arduino.cc/learn/communication/spi[Arduino & Serial Peripheral Interface (SPI)] guide.
26+
27+
--
28+
// OVERVIEW SECTION ENDS
29+
30+
31+
// FUNCTIONS SECTION STARTS
32+
[#functions]
33+
--
34+
35+
'''
36+
37+
[float]
38+
=== Functions
39+
link:../SPI/SPISettings[SPISettings] +
40+
link:../SPI/begin[begin()] +
41+
link:../SPI/beginTransaction[beginTransaction()] +
42+
link:../SPI/end[end()] +
43+
link:../SPI/setBitOrder[setBitOrder()] +
44+
link:../SPI/setClockDivider[setClockDivider()] +
45+
link:../SPI/setDataMode[setDataMode()] +
46+
link:../SPI/transfer[transfer()] +
47+
link:../SPI/usingInterrupt[usingInterrupt()]
48+
49+
'''
50+
51+
--
52+
// SEEALSO SECTION ENDS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: SPISettings
3+
---
4+
5+
= SPISettings
6+
7+
8+
// OVERVIEW SECTION STARTS
9+
[#overview]
10+
--
11+
12+
[float]
13+
=== Description
14+
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()`.
15+
16+
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.
17+
18+
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.
19+
20+
[float]
21+
=== Syntax
22+
`SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE0))`
23+
Note: Best if all 3 settings are constants
24+
25+
`SPISettings mySettting(speedMaximum, dataOrder, dataMode)`
26+
Note: Best when any setting is a variable''
27+
28+
29+
[float]
30+
=== Parameters
31+
`speedMaximum`: The maximum speed of communication. For a SPI chip rated up to 20 MHz, use 20000000. +
32+
`dataOrder`: MSBFIRST or LSBFIRST +
33+
`dataMode`: SPI_MODE0, SPI_MODE1, SPI_MODE2, or SPI_MODE3
34+
35+
36+
[float]
37+
=== Returns
38+
None.
39+
40+
--
41+
// OVERVIEW SECTION ENDS
42+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: SPI.begin()
3+
---
4+
5+
= SPI.begin()
6+
7+
8+
// OVERVIEW SECTION STARTS
9+
[#overview]
10+
--
11+
12+
[float]
13+
=== Description
14+
Initializes the SPI bus by setting SCK, MOSI, and SS to outputs, pulling SCK and MOSI low, and SS high.
15+
16+
17+
[float]
18+
=== Syntax
19+
`SPI.begin()`
20+
21+
22+
[float]
23+
=== Parameters
24+
None.
25+
26+
27+
[float]
28+
=== Returns
29+
None.
30+
31+
--
32+
// OVERVIEW SECTION ENDS
33+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: SPI.beginTransaction()
3+
---
4+
5+
= SPI.beginTransaction()
6+
7+
8+
// OVERVIEW SECTION STARTS
9+
[#overview]
10+
--
11+
12+
[float]
13+
=== Description
14+
Initializes the SPI bus using the defined link:SPISettings[SPISettings].
15+
16+
17+
[float]
18+
=== Syntax
19+
`SPI.beginTransaction(mySettings)`
20+
21+
22+
[float]
23+
=== Parameters
24+
mySettings: the chosen settings according to link:SPISettings[SPISettings].
25+
26+
27+
[float]
28+
=== Returns
29+
None.
30+
31+
--
32+
// OVERVIEW SECTION ENDS
33+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: SPI.end()
3+
---
4+
5+
= SPI.end()
6+
7+
8+
// OVERVIEW SECTION STARTS
9+
[#overview]
10+
--
11+
12+
[float]
13+
=== Description
14+
Disables the SPI bus (leaving pin modes unchanged).
15+
16+
17+
[float]
18+
=== Syntax
19+
`SPI.end()`
20+
21+
22+
[float]
23+
=== Parameters
24+
None.
25+
26+
27+
[float]
28+
=== Returns
29+
None.
30+
31+
--
32+
// OVERVIEW SECTION ENDS
33+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: SPI.endTransaction()
3+
---
4+
5+
= SPI.endTransaction()
6+
7+
8+
// OVERVIEW SECTION STARTS
9+
[#overview]
10+
--
11+
12+
[float]
13+
=== Description
14+
Stop using the SPI bus. Normally this is called after de-asserting the chip select, to allow other libraries to use the SPI bus.
15+
16+
17+
[float]
18+
=== Syntax
19+
`SPI.endTransaction()`
20+
21+
22+
[float]
23+
=== Parameters
24+
None.
25+
26+
27+
[float]
28+
=== Returns
29+
None.
30+
31+
--
32+
// OVERVIEW SECTION ENDS
33+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: SPI.setBitOrder()
3+
---
4+
5+
= SPI.setBitOrder()
6+
7+
8+
// OVERVIEW SECTION STARTS
9+
[#overview]
10+
--
11+
12+
[float]
13+
=== Description
14+
This function should not be used in new projects. Use link:SPISettings[SPISettings]. with link:beginTransaction[SPI.beginTransaction()]. to configure SPI parameters.
15+
16+
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).
17+
18+
19+
[float]
20+
=== Syntax
21+
`SPI.setBitOrder(order)`
22+
23+
24+
[float]
25+
=== Parameters
26+
order: either LSBFIRST or MSBFIRST
27+
28+
29+
[float]
30+
=== Returns
31+
None.
32+
33+
--
34+
// OVERVIEW SECTION ENDS
35+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: SPI.setClockDivider()
3+
---
4+
5+
= SPI.setClockDivider()
6+
7+
8+
// OVERVIEW SECTION STARTS
9+
[#overview]
10+
--
11+
12+
[float]
13+
=== Description
14+
This function should not be used in new projects. Use link:SPISettings[SPISettings]. with link:beginTransaction[SPI.beginTransaction()]. to configure SPI parameters.
15+
16+
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).
17+
18+
*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.
19+
20+
21+
[float]
22+
=== Syntax
23+
`SPI.setClockDivider(divider)`
24+
25+
26+
[float]
27+
=== Parameters
28+
29+
divider (only AVR boards):
30+
* SPI_CLOCK_DIV2
31+
* SPI_CLOCK_DIV4
32+
* SPI_CLOCK_DIV8
33+
* SPI_CLOCK_DIV16
34+
* SPI_CLOCK_DIV32
35+
* SPI_CLOCK_DIV64
36+
* SPI_CLOCK_DIV128
37+
38+
chipSelectPin: peripheral device CS pin (Arduino Due only)
39+
divider: a number from 1 to 255 (Arduino Due only)
40+
41+
[float]
42+
=== Returns
43+
None.
44+
45+
--
46+
// OVERVIEW SECTION ENDS
47+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: SPI.setDataMode()
3+
---
4+
5+
= SPI.setDataMode()
6+
7+
// OVERVIEW SECTION STARTS
8+
[#overview]
9+
--
10+
11+
[float]
12+
=== Description
13+
This function should not be used in new projects. Use link:SPISettings[SPISettings]. with link:beginTransaction[SPI.beginTransaction()]. to configure SPI parameters.
14+
15+
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.
16+
17+
[float]
18+
=== Syntax
19+
`SPI.setDataMode(mode)`
20+
21+
22+
[float]
23+
=== Parameters
24+
25+
mode:
26+
27+
* SPI_MODE0
28+
* SPI_MODE1
29+
* SPI_MODE2
30+
* SPI_MODE3
31+
32+
33+
chipSelectPin - peripheral device CS pin (Arduino Due only)
34+
35+
[float]
36+
=== Returns
37+
None.
38+
39+
--
40+
// OVERVIEW SECTION ENDS
41+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: SPI.transfer()
3+
---
4+
5+
= SPI.transfer()
6+
7+
// OVERVIEW SECTION STARTS
8+
[#overview]
9+
--
10+
11+
[float]
12+
=== Description
13+
14+
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).
15+
16+
[float]
17+
=== Syntax
18+
19+
`receivedVal = SPI.transfer(val)`
20+
21+
`receivedVal16 = SPI.transfer16(val16)`
22+
23+
`SPI.transfer(buffer, size)`
24+
25+
26+
[float]
27+
=== Parameters
28+
29+
* val: the byte to send out over the bus
30+
* val16: the two bytes variable to send out over the bus
31+
* buffer: the array of data to be transferred
32+
33+
34+
[float]
35+
=== Returns
36+
The received data.
37+
38+
--
39+
// OVERVIEW SECTION ENDS
40+

0 commit comments

Comments
 (0)