pxt-calliope/docs/reference/pins/spi-frequency.md

33 lines
898 B
Markdown
Raw Normal View History

2017-11-27 23:21:21 +01:00
# SPI Frequency
2017-05-26 02:19:25 +02:00
2017-11-27 23:21:21 +01:00
Set the SPI clock frequency.
2017-05-26 02:19:25 +02:00
```sig
2017-11-27 23:21:21 +01:00
pins.spiFrequency(1000000);
2017-05-26 02:19:25 +02:00
```
## Parameters
2017-05-26 02:19:25 +02:00
2017-11-27 23:21:21 +01:00
* **frequency**: a [number](/types/number) to set as the frequency for SPI bus clock. This value is the number of clock changes per second (Hz).
2017-05-26 02:19:25 +02:00
2017-11-27 23:21:21 +01:00
## Example
2017-05-26 02:19:25 +02:00
2017-11-27 23:21:21 +01:00
Read the value of the _WHOAMI_ register from the device connected to the SPI bus. The chip select line is connected to pin **0** and the SPI signals use pins **13**, **14**, and **15**.
```blocks
pins.digitalWritePin(DigitalPin.P0, 1);
pins.spiPins(DigitalPin.P15, DigitalPin.P14, DigitalPin.P13);
pins.spiFormat(8, 3);
pins.spiFrequency(1000000);
pins.digitalWritePin(DigitalPin.P0, 0);
let command = pins.spiWrite(143);
let whoami = pins.spiWrite(0);
pins.digitalWritePin(DigitalPin.P0, 1);
basic.showNumber(whoami);
serial.writeLine("WHOAMI register value: " + whoami)
```
2017-05-26 02:19:25 +02:00
## See also
2017-05-26 02:19:25 +02:00
[SPI](https://developer.mbed.org/handbook/SPI)