Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of SWSPI by
SWSPI_HD Class Reference
A software implemented SPI that can use any digital pins. More...
#include <SWSPI_HD.h>
Public Member Functions | |
| SWSPI_HD (PinName dio_pin, PinName sclk_pin, PinName cs_pin) | |
| Create SWSPI_HD object. | |
| ~SWSPI_HD () | |
| Destructor. | |
| void | format (int bits, int mode=0) |
| Specify SPI format. | |
| void | frequency (int hz=10000000) |
| Specify SPI clock frequency. | |
| int | write (int value) |
| Write data and read result. | |
Detailed Description
A software implemented SPI that can use any digital pins.
Useful when don't want to share a single SPI hardware among attached devices or when pinout doesn't match exactly to the target's SPI pins
#include "mbed.h" #include "SWSPI_HD.h" SWSPI_HD spi(D8, D7, D6); // dio, sclk (n)cs (Using Arduino form factor Board (NUCLEO-32F401RE) int main() { spi.format(8, 0); spi.frequency(10000000); cs.write(0); spi.write(0x9f); int jedecid = (spi.write(0) << 16) | (spi.write(0) << 8) | spi.write(0); cs.write(1); }
Definition at line 53 of file SWSPI_HD.h.
Constructor & Destructor Documentation
| SWSPI_HD | ( | PinName | dio_pin, |
| PinName | sclk_pin, | ||
| PinName | cs_pin | ||
| ) |
| ~SWSPI_HD | ( | ) |
Destructor.
Definition at line 35 of file SWSPI_HD.cpp.
Member Function Documentation
| void format | ( | int | bits, |
| int | mode = 0 |
||
| ) |
Specify SPI format.
- Parameters:
-
bits 8 or 16 are typical values mode 0, 1, 2, or 3 phase (bit1) and idle clock (bit0)
Definition at line 42 of file SWSPI_HD.cpp.
| void frequency | ( | int | hz = 10000000 ) |
Specify SPI clock frequency.
- Parameters:
-
hz frequency (optional, defaults to 10000000)
Definition at line 51 of file SWSPI_HD.cpp.
| int write | ( | int | value ) |
Write data and read result.
- Parameters:
-
value data to write (see format for bit size) returns value read from device
Definition at line 56 of file SWSPI_HD.cpp.
Generated on Wed Jul 13 2022 16:17:17 by
1.7.2
