SDK4.0 This document shows Ameba SDK 4.0 APIs

- Main Page
- Modules
- Data Structures
- Files

Enumerator
SPI
Ameba SDK » HAL

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

enum MBED_SPI_IDX

Enumerator
MBED_SPI0 | means SPI0
MBED_SPI1 | means SPI1

## Function Documentation

int spi_busy | ( | spi_t * | obj | ) |

Get SPI busy state.

Parameters

  obj | spi object define in application software.

Return values

  | current busy state

void spi_disable | ( | spi_t * | obj | ) |

Close SPI device clock.

Parameters

  obj | spi object define in application software.

Return values

  none |

void spi_enable | ( | spi_t * | obj | ) |

Open SPI device clock.

Parameters

  obj | spi object define in application software.

Return values

  none |

void spi_flush_rx_fifo | ( | spi_t * | obj | ) |

SPI device to flush rx fifo.

Parameters

  obj | spi 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

  obj | spi object define in application software.
  bits | data frame size, 4-16 supported.
  mode | this 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]
  slave | this 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

  obj | spi object define in application software.

Return values

  none |

void spi_frequency | ( | spi_t * | obj,
|  | int | hz
| ) |  |

Set SPI baudrate.

Parameters

  obj | spi master object define in application software.
  hz | baudrate 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

  obj | spi object define in application software.
  mosi | MOSI PinName according to pinmux spec.
  miso | MISO PinName according to pinmux spec.
  sclk | SCLK PinName according to pinmux spec.
  ssel | CS 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

  obj | spi master object define in application software.
  value | the data to transmit.

Return values

  | data received from slave

int spi_slave_read | ( | spi_t * | obj | ) |

Slave receive one frame use SPI.

Parameters

  obj | spi 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

  obj | spi 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

  obj | spi slave object define in application software.
  value | the data to transmit.

Return values

  none |