The official mbed C/C SDK provides the software platform and libraries to build your applications.
Fork of mbed by
SPI Class Reference
A SPI Master, used for communicating with SPI slave devices. More...
#include <SPI.h>
Public Member Functions | |
SPI (PinName mosi, PinName miso, PinName sclk) | |
Create a SPI master connected to the specified pins. | |
void | format (int bits, int mode=0) |
Configure the data transmission format. | |
void | frequency (int hz=1000000) |
Set the spi bus clock frequency. | |
virtual int | write (int value) |
Write to the SPI Slave and return the response. |
Detailed Description
A SPI Master, used for communicating with SPI slave devices.
The default format is set to 8-bits, mode 0, and a clock frequency of 1MHz
Most SPI devices will also require Chip Select and Reset signals. These can be controlled using <DigitalOut> pins
Example:
// Send a byte to a SPI slave, and record the response #include "mbed.h" SPI device(p5, p6, p7); // mosi, miso, sclk int main() { int response = device.write(0xFF); }
Definition at line 47 of file SPI.h.
Constructor & Destructor Documentation
SPI | ( | PinName | mosi, |
PinName | miso, | ||
PinName | sclk | ||
) |
Member Function Documentation
void format | ( | int | bits, |
int | mode = 0 |
||
) |
Configure the data transmission format.
- Parameters:
-
bits Number of bits per SPI frame (4 - 16) mode Clock polarity and phase mode (0 - 3)
mode | POL PHA -----+-------- 0 | 0 0 1 | 0 1 2 | 1 0 3 | 1 1
void frequency | ( | int | hz = 1000000 ) |
Set the spi bus clock frequency.
- Parameters:
-
hz SCLK frequency in hz (default = 1MHz)
Generated on Tue Jul 12 2022 21:08:34 by 1.7.2