XBee Firmware Library
1.6.0
|
Functions | |
ssize_t | spi_config (uint8_t brpree, uint8_t brdiv, uint8_t config) |
Initializes and configures the SPI module of the device. More... | |
ssize_t | spi_transfer (uint8_t ss_num, const void *txbuf, void *rxbuf, size_t len) |
Transfers and receives bytes from the SPI interface. When a byte is transferred the function tries to read a byte from the SPI interface if the given reception buffer is not NULL. More... | |
Platform-specific layer provides a consistent SPI API to upper layers of the driver.
This API contains the functions to configure and control the SPI module of the programmable XBee devices. The Serial Peripheral Interface Bus is a synchronous serial data link standard named by Motorola that operates in full duplex mode. Devices communicate in master/slave mode where the master device initiates the data frame. Multiple slave devices are allowed with individual slave select (chip select) lines.
Platform-specific layer provides a consistent SPI API to upper layers of the driver.
The spi_config() function needs as fourth parameter a byte containing the configuration masks for the SPI module. These masks are defined with macros and they are the following:
- Macros to configure the \b data \b structure: - \b SPI_CFG_BIT_MSB : Most Significant Bit first. - \b SPI_CFG_BIT_LSB : Less Significant Bit first. - Macros to configure the \b clock \b polarity: - \b SPI_CFG_CPOL_0 : Configures the base value of the clock to 0. - \b SPI_CFG_CPOL_1 : Configures the base value of the clock to 1. - Macros to configure the \b clock \b phase: - \b SPI_CFG_CPHA_0 : If the clock polarity is 0, the data are captured on the clock's rising edge and data are propagated on a falling edge. If the clock polarity is 1, the data are captured on clock's falling edge and data are propagated on a rising edge. - \b SPI_CFG_CPHA_1 : If the clock polarity is 0, the data are captured on the clock's falling edge and data are propagated on a rising edge. If the clock polarity is 1, data are captured on clock's rising edge and data are propagated on a falling edge.
Usage example:
Initializes and configures the SPI module of the device.
[in] | brpree | baud-rate pre-scaler value. The bus clock of the SPI module is divided by (value - 1). |
[in] | brdiv | baud-rate divider value. The input clock of the SPI module is divided by (2 ^ value + 1). |
[in] | config | a byte containing the configuration masks for the SPI interface. See SPI Macros for more information. |
int | 0 on success. |
Transfers and receives bytes from the SPI interface. When a byte is transferred the function tries to read a byte from the SPI interface if the given reception buffer is not NULL.
[in] | ss_num | Slave Select number of device. Use 0 if there is no Slave Select signal. |
[in] | txbuf | the buffer containing the bytes to be transferred. If you only want to receive bytes, configure this parameter as NULL. |
[out] | rxbuf | the buffer where the read bytes will be stored. If you only want to transfer an array of bytes, configure this parameter as NULL. |
[in] | len | the number of bytes to be transferred/received |
int | 0 on success |
ENODEV | invalid dev_t parameter (the specified device number is not correct) |