.\" man page for Munts Technologies Linux Simple I/O Library .\" .\" Copyright (C)2016-2023, Philip Munts dba Munts Technologies. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions are met: .\" .\" * Redistributions of source code must retain the above copyright notice, .\" this list of conditions and the following disclaimer. .\" .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" .\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE .\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" .TH libspi 2 "21 December 2018" "version 1" "Linux Simple I/O Library" .SH NAME .B libspi \-\- Linux Simple I/O Library: SPI Module .SH SYNOPSIS .nf .B #include .BI "void SPI_open(const char *" name ", int32_t " mode ", int32_t " wordsize "," .BI " int32_t " speed ", int32_t *" fd ", int32_t *" error ");" .BI "void SPI_close(int32_t " fd ", int32_t *" error ");" .BI "void SPI_transaction(int32_t " spifd ", int32_t " csfd ", void *" cmd "," .BI " int32_t " cmdlen ", int32_t " delayus ", void *" resp ", int32_t " resplen "," .BI " int32_t *" error ");" .fi Link with .BR -lsimpleio . .SH DESCRIPTION .nh All functions return either .B 0 (upon success) or an .B errno value (upon failure) in .IR *error . .PP .B SPI_open() opens an SPI slave device. The device name, .BR /dev/spidevx.x , must be passed in the .IR name parameter. The .I mode parameter specifies the SPI bus transfer mode, .BR 0 " to " 3 . The .I wordsize parameter specifies the SPI bus transfer unit size, usually .BR 8 ", " 16 ", or " 32 " bits." Some SPI controllers only allow 8-bit transfers. The .I 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 .IR *fd . .PP .B SPI_close() closes a previously opened SPI slave device. .PP .B 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 .IR cmd " and " cmdlen parameters, or .BR NULL " and " 0 for a receive only transaction. The .I 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 .IR resp " and " resplen parameters, or .BR NULL " and " 0 for a transmit only transaction. The .IR csfd parameter should be set to .BR 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. .SH SEE ALSO .BR libsimpleio "(2), " libadc "(2), " libdac "(2), " libevent "(2), " libgpio "(2)," .br .BR libhidraw "(2), " libi2c "(2), " libipv4 "(2), " liblinux "(2), " liblinx "(2)," .br .BR libpwm "(2), " libserial "(2), " libstream "(2), " libwatchdog "(2)" .SH AUTHOR Philip Munts dba Munts Technologies.