A SPI slave, used for communicating with a SPI master device. More...
#include <SPISlave.h>
Public Member Functions | |
SPISlave (PinName mosi, PinName miso, PinName sclk, PinName ssel) | |
Create a SPI slave connected to the specified pins. More... | |
void | format (int bits, int mode=0) |
Configure the data transmission format. More... | |
void | frequency (int hz=1000000) |
Set the SPI bus clock frequency. More... | |
int | receive (void) |
Polls the SPI to see if data has been received. More... | |
int | read (void) |
Retrieve data from receive buffer as slave. More... | |
void | reply (int value) |
Fill the transmission buffer with the value to be written out as slave on the next received message from the master. More... | |
A SPI slave, used for communicating with a SPI master device.
The default format is set to 8 bits, mode 0 and a clock frequency of 1MHz.
Example of how to reply to a SPI master as slave:
Definition at line 56 of file SPISlave.h.
SPISlave | ( | PinName | mosi, |
PinName | miso, | ||
PinName | sclk, | ||
PinName | ssel | ||
) |
void format | ( | int | bits, |
int | mode = 0 |
||
) |
Configure the data transmission format.
bits | Number of bits per SPI frame (4 - 16). |
mode | Clock polarity and phase mode (0 - 3). |
void frequency | ( | int | hz = 1000000 | ) |
Set the SPI bus clock frequency.
hz | Clock frequency in hz (default = 1MHz). |
int read | ( | void | ) |
Retrieve data from receive buffer as slave.
int receive | ( | void | ) |
Polls the SPI to see if data has been received.
0 | No data waiting. |
1 | Data waiting. |
void reply | ( | int | value | ) |
Fill the transmission buffer with the value to be written out as slave on the next received message from the master.
value | The data to be transmitted next. |