---
name: "spi_write_then_read"
section: "9"
platform: "linux"
package: "linux-manual-3.16"
version: "3.16.56-1+deb8u1"
release: "Debian 8 (Jessie)"
platforms: ["linux"]
url: "https://new.carta.tech/spi_write_then_read"
---

# spi\_write\_then\_read(9)

SPI synchronous write followed by read

## NAME

spi\_write\_then\_read - SPI synchronous write followed by read

## SYNOPSIS

**int spi\_write\_then\_read(struct spi\_device \*** *spi***, const void \*** *txbuf***, unsigned** *n\_tx***, void \*** *rxbuf***, unsigned** *n\_rx***);**

## ARGUMENTS

*spi*

device with which data will be exchanged

*txbuf*

data to be written (need not be dma-safe)

*n\_tx*

size of txbuf, in bytes

*rxbuf*

buffer into which data will be read (need not be dma-safe)

*n\_rx*

size of rxbuf, in bytes

## CONTEXT

can sleep

## DESCRIPTION

This performs a half duplex MicroWire style transaction with the device, sending txbuf and then reading rxbuf. The return value is zero for success, else a negative errno status code. This call may only be used from a context that may sleep.

Parameters to this routine are always copied using a small buffer; portable code should never use this for more than 32 bytes. Performance-sensitive or bulk transfer code should instead use spi\_{async,sync}() calls with dma-safe buffers.

## COPYRIGHT
