Martin Simpson / SWSPI_HD

Fork of SWSPI by Dave Van Wagner

Embed: (wiki syntax)

« Back to documentation index

SWSPI_HD Class Reference

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 
)

Create SWSPI_HD object.

Parameters:
dio
sclk_pin

Definition at line 26 of file SWSPI_HD.cpp.

~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:
bits8 or 16 are typical values
mode0, 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:
hzfrequency (optional, defaults to 10000000)

Definition at line 51 of file SWSPI_HD.cpp.

int write ( int  value )

Write data and read result.

Parameters:
valuedata to write (see format for bit size) returns value read from device

Definition at line 56 of file SWSPI_HD.cpp.