Atmel Software Framework

usart_spi.c File Reference

SAM USART in SPI mode driver functions.

Copyright (c) 2011-2016 Atmel Corporation. All rights reserved.

#include "usart_spi.h"
#include "sysclk.h"

Functions

void usart_spi_deselect_device (Usart *p_usart, struct usart_spi_device *device)
 De-select the given device on the SPI bus. More...
 
void usart_spi_disable (Usart *p_usart)
 Disable the USART for the specified USART in SPI mode. More...
 
void usart_spi_enable (Usart *p_usart)
 Enable the USART for the specified USART in SPI mode. More...
 
void usart_spi_init (Usart *p_usart)
 Enable the USART system clock in SPI master mode. More...
 
uint32_t usart_spi_is_rx_full (Usart *p_usart)
 Check if both receive buffers are full. More...
 
uint32_t usart_spi_is_rx_ready (Usart *p_usart)
 Check whether the USART in SPI master mode contains a received character. More...
 
uint32_t usart_spi_is_tx_empty (Usart *p_usart)
 Check whether there are data in Transmit Holding Register or Transmit Shift Register in SPI master mode. More...
 
uint32_t usart_spi_is_tx_ready (Usart *p_usart)
 Check if the USART Transmit Holding Register is empty or not in SPI mode. More...
 
uint32_t usart_spi_read_packet (Usart *p_usart, uint8_t *data, size_t len)
 Receive a sequence of bytes from a USART in SPI mode device. More...
 
void usart_spi_read_single (Usart *p_usart, uint8_t *data)
 Receive one byte from an SPI device using USART in SPI mode. More...
 
void usart_spi_select_device (Usart *p_usart, struct usart_spi_device *device)
 Select the given device on the SPI bus. More...
 
void usart_spi_setup_device (Usart *p_usart, struct usart_spi_device *device, spi_flags_t flags, unsigned long baud_rate, board_spi_select_id_t sel_id)
 Set up a USART in SPI master mode device. More...
 
uint32_t usart_spi_write_packet (Usart *p_usart, const uint8_t *data, size_t len)
 Send a sequence of bytes to an SPI device using USART in SPI mode. More...
 
void usart_spi_write_single (Usart *p_usart, uint8_t data)
 Write one byte to an SPI device using USART in SPI mode. More...
 

void usart_spi_deselect_device ( Usart *  p_usart,
struct usart_spi_device device 
)

De-select the given device on the SPI bus.

Parameters
p_usartBase address of the USART instance.
deviceSPI device.

References UNUSED, and usart_spi_release_chip_select().

Referenced by at25dfx_spi_deselect_device(), ssd1306_write_command(), and ssd1306_write_data().

void usart_spi_disable ( Usart *  p_usart)

Disable the USART for the specified USART in SPI mode.

Ensure that nothing is transferred while setting up buffers.

Parameters
p_usartBase address of the USART instance.

References usart_disable_rx(), and usart_disable_tx().

void usart_spi_enable ( Usart *  p_usart)

Enable the USART for the specified USART in SPI mode.

Parameters
p_usartBase address of the USART instance.

References usart_enable_rx(), and usart_enable_tx().

void usart_spi_init ( Usart *  p_usart)

Enable the USART system clock in SPI master mode.

Parameters
p_usartPointer to Base address of the USART instance.

References flexcom_enable(), flexcom_set_opmode(), FLEXCOM_USART, and sysclk_enable_peripheral_clock().

Referenced by at25dfx_spi_init(), at45dbx_spi_init(), and ssd1306_interface_init().

uint32_t usart_spi_is_rx_full ( Usart *  p_usart)

Check if both receive buffers are full.

Parameters
p_usartBase address of the USART instance.
Return values
1Receive buffers are full.
0Receive buffers are not full.

References usart_is_rx_buf_full().

uint32_t usart_spi_is_rx_ready ( Usart *  p_usart)

Check whether the USART in SPI master mode contains a received character.

Parameters
p_usartBase address of the USART instance.
Return values
1Some data have been received.
0No data has been received.

References usart_is_rx_ready().

uint32_t usart_spi_is_tx_empty ( Usart *  p_usart)

Check whether there are data in Transmit Holding Register or Transmit Shift Register in SPI master mode.

Parameters
p_usartBase address of the USART instance.
Return values
1The two registers are empty.
0One of the two registers contains data.

References usart_is_tx_empty().

uint32_t usart_spi_is_tx_ready ( Usart *  p_usart)

Check if the USART Transmit Holding Register is empty or not in SPI mode.

Parameters
p_usartBase address of the USART instance.
Return values
1There is no data in the Transmit Holding Register.
0There are data in the Transmit Holding Register.

References usart_is_tx_ready().

uint32_t usart_spi_read_packet ( Usart *  p_usart,
uint8_t *  data,
size_t  len 
)

Receive a sequence of bytes from a USART in SPI mode device.

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

Parameters
p_usartBase address of the usart instance.
dataData buffer to put read data.
lenLength of data.
Returns
0 if the USART in SPI master mode reads packet successfully.
Precondition
USART device must be selected with usart_spi_select_device() first.

References CONFIG_USART_SPI_DUMMY, usart_getchar(), and usart_putchar().

Referenced by at25dfx_spi_read_byte(), and at25dfx_spi_read_packet().

void usart_spi_read_single ( Usart *  p_usart,
uint8_t *  data 
)

Receive one byte from an SPI device using USART in SPI mode.

Parameters
p_usartBase address of the USART instance.
dataPointer to the data byte where to store the received data.
Precondition
USART device must be selected with usart_spi_select_device() first.

References CONFIG_USART_SPI_DUMMY, usart_getchar(), and usart_putchar().

void usart_spi_select_device ( Usart *  p_usart,
struct usart_spi_device device 
)

Select the given device on the SPI bus.

Parameters
p_usartBase address of the USART instance.
deviceSPI device.

References UNUSED, and usart_spi_force_chip_select().

Referenced by at25dfx_spi_select_device(), ssd1306_write_command(), and ssd1306_write_data().

void usart_spi_setup_device ( Usart *  p_usart,
struct usart_spi_device device,
spi_flags_t  flags,
unsigned long  baud_rate,
board_spi_select_id_t  sel_id 
)

Set up a USART in SPI master mode device.

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

Parameters
p_usartBase address of the USART instance.
devicePointer to usart device struct that should be initialized.
flagsUSART configuration flags. Common flags for all implementations are the usart modes, which should be SPI_MODE_0, SPI_MODE_1, SPI_MODE_2, SPI_MODE_3.
baud_rateBaud rate for communication with slave device in Hz.
sel_idBoard specific select id.

References usart_spi_opt_t::baudrate, usart_spi_opt_t::channel_mode, usart_spi_opt_t::char_length, usart_spi_opt_t::spi_mode, sysclk_get_peripheral_hz(), UNUSED, usart_enable_rx(), usart_enable_tx(), and usart_init_spi_master().

Referenced by at25dfx_spi_init(), and ssd1306_interface_init().

uint32_t usart_spi_write_packet ( Usart *  p_usart,
const uint8_t *  data,
size_t  len 
)

Send a sequence of bytes to an SPI device using USART in SPI mode.

Received bytes on the USART in SPI mode are discarded.

Parameters
p_usartBase address of the USART instance.
dataData buffer to write.
lenLength of data.
Returns
0 if the USART in SPI master mode sends packet successfully.
Precondition
USART device must be selected with usart_spi_select_device() first.

References usart_getchar(), and usart_putchar().

Referenced by at25dfx_spi_write_byte(), and at25dfx_spi_write_packet().

void usart_spi_write_single ( Usart *  p_usart,
uint8_t  data 
)

Write one byte to an SPI device using USART in SPI mode.

Parameters
p_usartBase address of the USART instance.
dataThe data to be sent out.

References usart_putchar().