Atmel Software Framework

spi_master.c File Reference
#include "spi_master.h"

Functions

void spi_master_setup_device (volatile avr32_spi_t *spi, struct spi_device *device, spi_flags_t flags, uint32_t baud_rate, board_spi_select_id_t sel_id)
 Setup a SPI device. More...
 
status_code_t spi_read_packet (volatile avr32_spi_t *spi, uint8_t *data, size_t len)
 Receive a sequence of bytes from a SPI device. More...
 
status_code_t spi_write_packet (volatile avr32_spi_t *spi, const uint8_t *data, size_t len)
 Send a sequence of bytes to a SPI device. More...
 

void spi_master_setup_device ( volatile avr32_spi_t *  spi,
struct spi_device device,
spi_flags_t  flags,
uint32_t  baud_rate,
board_spi_select_id_t  sel_id 
)

Setup a SPI device.

The returned device descriptor structure must be passed to the driver whenever that device should be used as current slave device.

Parameters
spiBase address of the SPI instance.
devicePointer to SPI device struct that should be initialized.
flagsSPI configuration flags. Common flags for all implementations are the SPI modes SPI_MODE_0 ... SPI_MODE_3.
baud_rateBaud rate for communication with slave device in Hz.
sel_idBoard specific select id

References CONFIG_SPI_MASTER_BITS_PER_TRANSFER, CONFIG_SPI_MASTER_DELAY_BCT, CONFIG_SPI_MASTER_DELAY_BS, getBaudDiv(), spi_device::id, spi_enable_active_mode(), spi_set_baudrate_register(), spi_set_bits_per_transfer(), spi_set_chipselect_delay_bct(), spi_set_chipselect_delay_bs(), spi_set_mode(), sysclk_get_peripheral_bus_hz(), and vSemaphoreCreateBinary.

Referenced by at25dfx_spi_init(), ili9341_interface_init(), and main().

status_code_t spi_read_packet ( volatile avr32_spi_t *  spi,
uint8_t *  data,
size_t  len 
)

Receive a sequence of bytes from a SPI device.

All bytes sent out on SPI bus are sent as value 0.

Parameters
spiBase address of the SPI instance.
dataData buffer to read
lenLength of data
Precondition
SPI device must be selected with spi_select_device() first

References CONFIG_SPI_MASTER_DUMMY, ERR_TIMEOUT, i, spi_is_rx_ready(), spi_is_tx_ready(), spi_read_single(), SPI_TIMEOUT, spi_write_single(), STATUS_OK, and val.

Referenced by at25dfx_spi_read_byte(), at25dfx_spi_read_packet(), and spi_at45dbx_mem_check().

status_code_t spi_write_packet ( volatile avr32_spi_t *  spi,
const uint8_t *  data,
size_t  len 
)

Send a sequence of bytes to a SPI device.

Received bytes on the SPI bus are discarded.

Parameters
spiBase address of the SPI instance.
dataData buffer to write
lenLength of data
Precondition
SPI device must be selected with spi_select_device() first

References ERR_TIMEOUT, i, spi_is_tx_ready(), SPI_TIMEOUT, spi_write_single(), STATUS_OK, and val.

Referenced by at25dfx_spi_write_byte(), at25dfx_spi_write_packet(), and spi_at45dbx_mem_check().