XBee Firmware Library  1.6.0
Functions
Serial Peripheral Interface (SPI)

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...
 

Detailed Description

Platform-specific layer provides a consistent SPI API to upper layers of the driver.

SPI API Overview

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.

SPI Macros

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:

spi_config(spi_0, 1, 1, SPI_CFG_BIT_MSB | SPI_CFG_SS_DISABLE | SPI_CFG_CPOL_0 | SPI_CFG_MODE_SLAVE);
Warning
It is recommended not to use these macros, they are used by the XBee Project Smart Editor of the XBee extensions.

Function Documentation

ssize_t spi_config ( uint8_t  brpree,
uint8_t  brdiv,
uint8_t  config 
)

Initializes and configures the SPI module of the device.

Parameters
[in]brpreebaud-rate pre-scaler value. The bus clock of the SPI module is divided by (value - 1).
[in]brdivbaud-rate divider value. The input clock of the SPI module is divided by (2 ^ value + 1).
[in]configa byte containing the configuration masks for the SPI interface. See SPI Macros for more information.
Return values
int0 on success.
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.

Parameters
[in]ss_numSlave Select number of device. Use 0 if there is no Slave Select signal.
[in]txbufthe buffer containing the bytes to be transferred. If you only want to receive bytes, configure this parameter as NULL.
[out]rxbufthe buffer where the read bytes will be stored. If you only want to transfer an array of bytes, configure this parameter as NULL.
[in]lenthe number of bytes to be transferred/received
Return values
int0 on success
ENODEVinvalid dev_t parameter (the specified device number is not correct)