Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
|
SPI Master Hardware Abstraction Layer API Reference. More...
Functions | |
void | hal_spi_master_configure_default (hal_spi_master_config_t *config) |
Configure SPI Master configuration structure with default values. More... | |
err_t | hal_spi_master_open (handle_t *handle, bool hal_obj_open_state) |
Open the SPI Master HAL object on selected pins. More... | |
void | hal_spi_master_select_device (hal_pin_name_t chip_select) |
Select SPI Slave device. More... | |
void | hal_spi_master_deselect_device (hal_pin_name_t chip_select) |
Deselect SPI Slave device. More... | |
void | hal_spi_master_set_chip_select_polarity (hal_spi_master_chip_select_polarity_t polarity) |
Set desired chip select polarity. More... | |
void | hal_spi_master_set_default_write_data (handle_t *handle, hal_spi_master_config_t *config) |
Set SPI Master default ( dummy ) write data. More... | |
err_t | hal_spi_master_write (handle_t handle, uint8_t *write_data_buffer, size_t write_data_length) |
Write byte to SPI bus. More... | |
err_t | hal_spi_master_read (handle_t handle, uint8_t *read_data_buffer, size_t read_data_length) |
Read byte from SPI bus. More... | |
err_t | hal_spi_master_write_then_read (handle_t handle, uint8_t *write_data_buffer, size_t length_write_data, uint8_t *read_data_buffer, size_t length_read_data) |
Perform a sequence of SPI Master writes immediately followed by a SPI Master read. More... | |
err_t | hal_spi_master_close (handle_t *handle) |
Close SPI Master HAL context object. More... | |
err_t | hal_spi_master_set_speed (handle_t *handle, hal_spi_master_config_t *config) |
Set desired SPI communication speed. More... | |
err_t | hal_spi_master_set_mode (handle_t *handle, hal_spi_master_config_t *config) |
Set desired SPI communication mode. More... | |
SPI Master Hardware Abstraction Layer API Reference.
API for configuring and manipulating SPI Master HAL module.
Close SPI Master HAL context object.
Closes SPI Master HAL context object, resets pin AF to default values and clears all buffers used by object.
[in,out] | handle | SPI master handle. See hal_spi_master_t structure definition for detailed explanation. |
Example
void hal_spi_master_configure_default | ( | hal_spi_master_config_t * | config | ) |
Configure SPI Master configuration structure with default values.
Configures structure to default initialization values. Take into consideration that this is just structure variable initial values setting. Values need to be redefined by user.
[in,out] | config | SPI Master HAL layer configuration settings. See hal_spi_master_config_t structure definition for detailed explanation. |
Default values:
Function | Default value |
---|---|
SPI SCK pin | HAL_PIN_NC (invalid pin) |
SPI MISO pin | HAL_PIN_NC (invalid pin) |
SPI MOSI pin | HAL_PIN_NC (invalid pin) |
SPI Speed | 100KHz |
SPI mode | 0 |
SPI default write data | 0 |
Example
void hal_spi_master_deselect_device | ( | hal_pin_name_t | chip_select | ) |
Deselect SPI Slave device.
Sets digital output individual slave pin to logic 1.
[in] | chip_select | Device-specific chip select pin. |
Example
Open the SPI Master HAL object on selected pins.
Opens the SPI Master HAL object on selected pins. Allocates memory and pin for specified object.
[in] | handle | SPI Master HAL object. See hal_spi_master_t structure definition for detailed explanation. |
[in] | hal_obj_open_state | SPI Master configuration structure. See hal_spi_master_config_t structure definition for detailed explanation. |
Example
Read byte from SPI bus.
Reads byte from SPI bus in blocking mode. Transmitted byte is user-defined default (dummy) write data.
[in] | handle | SPI master handle. See hal_spi_master_t structure definition for detailed explanation. |
[out] | read_data_buffer | Read buffer. |
[in] | read_data_length | Number of bytes to be read. |
Example
void hal_spi_master_select_device | ( | hal_pin_name_t | chip_select | ) |
Select SPI Slave device.
Sets digital output individual slave pin to logic 0.
[in] | chip_select | Device-specific chip select pin. |
Example
void hal_spi_master_set_chip_select_polarity | ( | hal_spi_master_chip_select_polarity_t | polarity | ) |
Set desired chip select polarity.
Sets SPI Master chip select polarity either to active low or active high. Chip select polarity shall be active low by default.
[in] | polarity | Desired chip select polarity mode. See hal_spi_master_chip_select_polarity_t for valid values. |
Example
void hal_spi_master_set_default_write_data | ( | handle_t * | handle, |
hal_spi_master_config_t * | config | ||
) |
Set SPI Master default ( dummy ) write data.
Default write data is sent by driver when the data transmit buffer is shorter than data receive buffer.
[in] | handle | SPI master handle. See hal_spi_master_t structure definition for detailed explanation. |
[in] | config | HAL SPI Master config structure. See hal_spi_master_config_t structure definition for detailed explanation. |
Example
err_t hal_spi_master_set_mode | ( | handle_t * | handle, |
hal_spi_master_config_t * | config | ||
) |
Set desired SPI communication mode.
Sets SPI Master module mode to passed value if possible. If not possible, returns error. Make sure to check for return value. Initializes SPI module on hardware level.
[in] | handle | SPI master handle. See hal_spi_master_t structure definition for detailed explanation. |
[in] | config | HAL SPI Master config structure. See hal_spi_master_config_t structure definition for detailed explanation. |
Example
err_t hal_spi_master_set_speed | ( | handle_t * | handle, |
hal_spi_master_config_t * | config | ||
) |
Set desired SPI communication speed.
Sets SPI Master module speed to passed value if possible. If not possible, returns error. Make sure to check for return value. Initializes SPI module on hardware level.
[in] | handle | SPI master handle. See hal_spi_master_t structure definition for detailed explanation. |
[in] | config | HAL SPI Master config structure. See hal_spi_master_config_t structure definition for detailed explanation. |
Example
err_t hal_spi_master_write | ( | handle_t | handle, |
uint8_t * | write_data_buffer, | ||
size_t | write_data_length | ||
) |
Write byte to SPI bus.
Writes byte to SPI bus in blocking mode. Received byte is discarded.
[in] | handle | SPI master handle. See hal_spi_master_t structure definition for detailed explanation. |
[in] | write_data_buffer | Value to send. |
[in] | write_data_length | Number of bytes to write from data buffer. |
Example
err_t hal_spi_master_write_then_read | ( | handle_t | handle, |
uint8_t * | write_data_buffer, | ||
size_t | length_write_data, | ||
uint8_t * | read_data_buffer, | ||
size_t | length_read_data | ||
) |
Perform a sequence of SPI Master writes immediately followed by a SPI Master read.
Writes a sequence of bytes to SPI bus, followed by a corresponding read.
[in] | handle | SPI master handle. See hal_spi_master_t structure definition for detailed explanation. |
[in] | write_data_buffer | Value to send. |
[in] | length_write_data | Number of bytes to write from data buffer. |
[out] | read_data_buffer | Read buffer. |
[in] | length_read_data | Number of bytes to be read. |
Example