SDK4.0
This document shows Ameba SDK 4.0 APIs
Enumerator

spi functions More...

AmebaZ Only

enum  MBED_SPI_IDX { MBED_SPI0 = 0xF0, MBED_SPI1 = 0xF1 }
 

Ameba Common

typedef struct spi_s spi_t
 
void spi_init (spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
 Initializes the SPI device, include clock/function/interrupt/SPI registers. More...
 
void spi_free (spi_t *obj)
 Deinitializes the SPI device, include interrupt/DMA/DISABLE SPI. More...
 
void spi_format (spi_t *obj, int bits, int mode, int slave)
 Set SPI format,include DFS/Phase/Polarity. More...
 
void spi_frequency (spi_t *obj, int hz)
 Set SPI baudrate. More...
 
int spi_master_write (spi_t *obj, int value)
 Master send one frame use SPI. More...
 
int spi_slave_receive (spi_t *obj)
 Get slave readable && busy state. More...
 
int spi_slave_read (spi_t *obj)
 Slave receive one frame use SPI. More...
 
void spi_slave_write (spi_t *obj, int value)
 Slave send one frame use SPI. More...
 
int spi_busy (spi_t *obj)
 Get SPI busy state. More...
 
void spi_flush_rx_fifo (spi_t *obj)
 SPI device to flush rx fifo. More...
 
void spi_enable (spi_t *obj)
 Open SPI device clock. More...
 
void spi_disable (spi_t *obj)
 Close SPI device clock. More...
 

Detailed Description

spi functions

Enumeration Type Documentation

Enumerator
MBED_SPI0 

means SPI0

MBED_SPI1 

means SPI1

Function Documentation

int spi_busy ( spi_t *  obj)

Get SPI busy state.

Parameters
objspi object define in application software.
Return values
current busy state
void spi_disable ( spi_t *  obj)

Close SPI device clock.

Parameters
objspi object define in application software.
Return values
none
void spi_enable ( spi_t *  obj)

Open SPI device clock.

Parameters
objspi object define in application software.
Return values
none
void spi_flush_rx_fifo ( spi_t *  obj)

SPI device to flush rx fifo.

Parameters
objspi object define in application software.
Return values
none
void spi_format ( spi_t *  obj,
int  bits,
int  mode,
int  slave 
)

Set SPI format,include DFS/Phase/Polarity.

Parameters
objspi object define in application software.
bitsdata frame size, 4-16 supported.
modethis parameter can be one of the following values:
  • 0 : [Polarity,Phase]=[0,0]
  • 1 : [Polarity,Phase]=[0,1]
  • 2 : [Polarity,Phase]=[1,0]
  • 3 : [Polarity,Phase]=[1,1]
slavethis parameter can be one of the following values:
  • 0 : indicates role-master
  • 1 : indicates role-slave
Return values
none
void spi_free ( spi_t *  obj)

Deinitializes the SPI device, include interrupt/DMA/DISABLE SPI.

Parameters
objspi object define in application software.
Return values
none
void spi_frequency ( spi_t *  obj,
int  hz 
)

Set SPI baudrate.

Parameters
objspi master object define in application software.
hzbaudrate for SPI bus
Return values
none
Note
"hz" should be less or equal to half of the SPI IpClk
void spi_init ( spi_t *  obj,
PinName  mosi,
PinName  miso,
PinName  sclk,
PinName  ssel 
)

Initializes the SPI device, include clock/function/interrupt/SPI registers.

Parameters
objspi object define in application software.
mosiMOSI PinName according to pinmux spec.
misoMISO PinName according to pinmux spec.
sclkSCLK PinName according to pinmux spec.
sselCS PinName according to pinmux spec.
Return values
none
Note
must set obj->spi_index to MBED_SPI0 or MBED_SPI1 before using spi_init
int spi_master_write ( spi_t *  obj,
int  value 
)

Master send one frame use SPI.

Parameters
objspi master object define in application software.
valuethe data to transmit.
Return values
data received from slave
int spi_slave_read ( spi_t *  obj)

Slave receive one frame use SPI.

Parameters
objspi slave object define in application software.
Return values
data received from master
int spi_slave_receive ( spi_t *  obj)

Get slave readable && busy state.

Parameters
objspi slave object define in application software.
Return values
slave Readable && Busy State
void spi_slave_write ( spi_t *  obj,
int  value 
)

Slave send one frame use SPI.

Parameters
objspi slave object define in application software.
valuethe data to transmit.
Return values
none