Modification of mbed-src library only for STM32F030F4, very cheap microcontroller in 20-Pin TSSOP package, with 16Kbytes of Flash and 4Kbytes of Ram. **Target for online compilator must be Nucleo 32F030R8.**

Dependents:   STM32F031_blink_LED_2

Embed: (wiki syntax)

« Back to documentation index

SPI Class Reference

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, PinName _unused=NC)
 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,
PinName  _unused = NC 
)

Create a SPI master connected to the specified pins.

Pin Options: (5, 6, 7) or (11, 12, 13)

mosi or miso can be specfied as NC if not used

Parameters:
mosiSPI Master Out, Slave In pin
misoSPI Master In, Slave Out pin
sclkSPI Clock pin

Definition at line 22 of file SPI.cpp.


Member Function Documentation

void format ( int  bits,
int  mode = 0 
)

Configure the data transmission format.

Parameters:
bitsNumber of bits per SPI frame (4 - 16)
modeClock polarity and phase mode (0 - 3)
 mode | POL PHA
 -----+--------
   0  |  0   0
   1  |  0   1
   2  |  1   0
   3  |  1   1

Definition at line 32 of file SPI.cpp.

void frequency ( int  hz = 1000000 )

Set the spi bus clock frequency.

Parameters:
hzSCLK frequency in hz (default = 1MHz)

Definition at line 39 of file SPI.cpp.

int write ( int  value ) [virtual]

Write to the SPI Slave and return the response.

Parameters:
valueData to be sent to the SPI slave
Returns:
Response from the SPI slave

Definition at line 56 of file SPI.cpp.