mikroSDK Reference Manual
|
SPI Master Driver API Reference. More...
Functions list | |
void | spi_master_configure_default (spi_master_config_t *config) |
Configure SPI Master configuration structure. More... | |
err_t | spi_master_open (spi_master_t *obj, spi_master_config_t *config) |
Open the SPI Master driver object on selected pins. More... | |
void | spi_master_select_device (pin_name_t chip_select) |
Select SPI Slave device. More... | |
void | spi_master_deselect_device (pin_name_t chip_select) |
Deselect SPI Slave device. More... | |
void | spi_master_set_chip_select_polarity (spi_master_chip_select_polarity_t polarity) |
Set desired SPI Master chip select polarity. More... | |
err_t | spi_master_set_default_write_data (spi_master_t *obj, uint8_t default_write_data) |
Set SPI Master driver default ( dummy ) write data. More... | |
err_t | spi_master_set_speed (spi_master_t *obj, uint32_t speed) |
Set SPI Master driver communication speed. More... | |
err_t | spi_master_set_mode (spi_master_t *obj, spi_master_mode_t mode) |
Set SPI Master driver communication mode. More... | |
err_t | spi_master_write (spi_master_t *obj, uint8_t *__generic_ptr write_data_buffer, size_t write_data_length) |
Write byte to SPI bus. More... | |
err_t | spi_master_read (spi_master_t *obj, uint8_t *read_data_buffer, size_t read_data_length) |
Read byte from SPI bus. More... | |
err_t | spi_master_write_then_read (spi_master_t *obj, 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 | spi_master_close (spi_master_t *obj) |
Close SPI Master Driver context object. More... | |
SPI Master Driver API header. Contains all enums, structures and function declarations available for SPI Master module.
void spi_master_configure_default | ( | spi_master_config_t * | config | ) |
Configures spi_master_config_t 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 driver configuration settings. See spi_master_config_t structure definition for detailed explanation. |
Default values:
Function | Default value |
---|---|
SPI SCK pin | 0xFFFFFFFF (invalid pin) |
SPI MISO pin | 0xFFFFFFFF (invalid pin) |
SPI MOSI pin | 0xFFFFFFFF (invalid pin) |
SPI Speed | 100KHz |
SPI mode | 0 |
SPI default write data | 0 |
Example
err_t spi_master_open | ( | spi_master_t * | obj, |
spi_master_config_t * | config | ||
) |
Opens the SPI Master driver object on selected pins. Allocates memory and pin for specified object.
[in] | obj | SPI Master driver object. See spi_master_t structure definition for detailed explanation. |
[in] | config | SPI Master configuration structure. See spi_master_config_t structure definition for detailed explanation. |
Example
void spi_master_select_device | ( | pin_name_t | chip_select | ) |
Sets digital output individual slave pin to logic 0.
[in] | chip_select | Device-specific chip select pin. |
Example
void spi_master_deselect_device | ( | pin_name_t | chip_select | ) |
Sets digital output individual slave pin to logic 1.
[in] | chip_select | Device-specific chip select pin. |
Example
void spi_master_set_chip_select_polarity | ( | spi_master_chip_select_polarity_t | 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 spi_master_chip_select_polarity_t for valid values. |
Example
err_t spi_master_set_default_write_data | ( | spi_master_t * | obj, |
uint8_t | default_write_data | ||
) |
Default write data is sent by driver when the data transmit buffer is shorter than data receive buffer.
[in] | obj | SPI master driver object. See spi_master_t structure definition for detailed explanation. |
[in] | default_write_data | User-defined default write data. |
Example
err_t spi_master_set_speed | ( | spi_master_t * | obj, |
uint32_t | 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] | obj | SPI Master driver object. See spi_master_t structure definition for detailed explanation. |
[in] | speed | SPI Master communication speed. |
Example
err_t spi_master_set_mode | ( | spi_master_t * | obj, |
spi_master_mode_t | 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] | obj | SPI Master driver object. See spi_master_t structure definition for detailed explanation. |
[in] | mode | SPI Master communication mode. See spi_master_mode_t for valid values. |
Example
err_t spi_master_write | ( | spi_master_t * | obj, |
uint8_t *__generic_ptr | write_data_buffer, | ||
size_t | write_data_length | ||
) |
Writes byte to SPI bus in blocking mode. Received byte is discarded.
[in] | obj | SPI master driver object. See spi_master_t structure definition for detailed explanation. |
[in] | write_data_buffer | Data transmit buffer. |
[in] | write_data_length | Number of bytes to write from data transmit buffer. |
Example
err_t spi_master_read | ( | spi_master_t * | obj, |
uint8_t * | read_data_buffer, | ||
size_t | read_data_length | ||
) |
Reads byte from SPI bus in blocking mode. Transmitted byte is user-defined default (dummy) write data.
[in] | obj | SPI master driver object. See spi_master_t structure definition for detailed explanation. |
[out] | read_data_buffer | Data receive buffer. |
[in] | read_data_length | Number of bytes to be read. |
Example
err_t spi_master_write_then_read | ( | spi_master_t * | obj, |
uint8_t * | write_data_buffer, | ||
size_t | length_write_data, | ||
uint8_t * | read_data_buffer, | ||
size_t | length_read_data | ||
) |
Writes a sequence of bytes to SPI bus, followed by a corresponding read.
[in] | obj | SPI master driver object. See spi_master_t structure definition for detailed explanation. |
[in] | write_data_buffer | Data transmit buffer. |
[in] | length_write_data | Number of bytes to write from data transmit buffer. |
[out] | read_data_buffer | Data receive buffer. |
[in] | length_read_data | Number of bytes to be read. |
Example
err_t spi_master_close | ( | spi_master_t * | obj | ) |
Closes SPI Master Driver context object, resets pin AF to default values and clears all buffers used by object.
[in,out] | obj | Driver context object handle. See spi_master_t structure definition for detailed explanation. |
Example