SPIMaster_Open Function

Header: #include <applibs/spi.h>

Opens and configures an SPI master interface for exclusive use, and returns a file descriptor to use for subsequent calls.

The interface is initialized with the default settings: SPI_Mode_0, SPI_BitOrder_MsbFirst. You can change these settings with SPI functions after the interface is opened.

static inline int SPIMaster_Open(SPI_InterfaceId interfaceId, SPI_ChipSelectId chipSelectId, const SPIMaster_Config *config);

Parameters

  • interfaceId The ID of the SPI master interface to open.

  • chipSelectId The chip select ID to use with the SPI master interface.

  • config The configuration for the SPI master interface. Before you call this function, you must call SPIMaster_InitConfig to initialize the SPIMaster_Config struct. You can change the settings after the struct is initialized. The config argument contains all settings that must be configured as part of opening the interface, and which may not be changed afterwards.

Errors

Returns -1 if an error is encountered and sets errno to the error value.

  • EACCES: access to this SPI interface is not permitted because the interfaceId parameter is not listed in the SpiMaster field of the application manifest.

Any other errno may also be specified; such errors aren't deterministic and the same behavior might not be retained through system updates.

Return value

Returns the file descriptor of the SPI interface if it was opened successfully, or -1 for failure, in which case errno is set to the error value. You may use this descriptor with standard read(2) and write(2) functions to transact with the connected device. You may also use SPIMaster_TransferSequential to run a sequence of transfers.

Application manifest requirements

To access individual SPI interfaces, your application must identify them in the SpiMaster field of the application manifest.