libspi

Section: Linux Simple I/O Library (2)
Updated: 21 December 2018
Index Return to Main Contents
 

NAME

libspi -- Linux Simple I/O Library: SPI Module  

SYNOPSIS

#include <libsimpleio/libspi.h>

void SPI_open(const char *name, int32_t mode, int32_t wordsize,
  int32_t speed, int32_t *fd, int32_t * error);

void SPI_close(int32_t fd, int32_t *error);

void SPI_transaction(int32_t spifd, int32_t csfd, void *cmd,
  int32_t cmdlen, int32_t delayus, void *resp, int32_t resplen,
  int32_t *error);

Link with -lsimpleio.  

DESCRIPTION

All functions return either 0 (upon success) or an errno value (upon failure) in *error.

SPI_open() opens an SPI slave device. The device name, /dev/spidevx.x, must be passed in the name parameter. The mode parameter specifies the SPI bus transfer mode, 0 to 3. The wordsize parameter specifies the SPI bus transfer unit size, usually 8, 16, or 32 bits. Some SPI controllers only allow 8-bit transfers. The speed parameter specifies the SPI bus transfer speed in bits per second. Upon success, a file descriptor for the SPI slave device is returned in *fd.

SPI_close() closes a previously opened SPI slave device.

SPI_transaction() performs a single SPI bus transaction, with optional transmit and receive phases. Either the address of a command message and its length must be passed in the cmd and cmdlen parameters, or NULL and 0 for a receive only transaction. The delayus parameter indicates the time in microseconds between the transmit and receive phases. It should be set long enough for the SPI slave device to execute the command and generate its response. Either the address of a receive buffer and its size must be passed in the resp and resplen parameters, or NULL and 0 for a transmit only transaction. The csfd parameter should be set to SPI_CS_AUTO to use the hardware controlled slave chip select signal or set to the open file descriptor for a GPIO pin to use for the software controlled slave chip select signal.  

SEE ALSO

libsimpleio(2), libadc(2), libdac(2), libevent(2), libgpio(2),
libhidraw(2), libi2c(2), libipv4(2), liblinux(2), liblinx(2),
libpwm(2), libserial(2), libstream(2), libwatchdog(2)  

AUTHOR

Philip Munts, President, Munts AM Corp dba Munts Technologies


 

Index

NAME
SYNOPSIS
DESCRIPTION
SEE ALSO
AUTHOR

This document was created by man2html, using the manual pages.
Time: 09:41:20 GMT, December 21, 2018