spi_write_read()


Transmitting data to the SPI and reading data from the SPI simultaneously

Description

int spi_write_read(int $spi_id, string $wbuf, string &$rbuf, int $rlen)

Parameters

Return Value

data length to read/write (byte)

Example

<?php
include "/lib/sd_340.php";
$rbuf = "";
$wbuf = "\x1E\x07";
$rlen = 0;
spi_setup(0);                                // configuring SPI
$rlen = spi_write_read(0, $wbuf, $rbuf, 2);  // writing and reading to/from the SPI
if($rlen == 2)
  echo "$rbuf\r\n";                          // outputting the received data
?>

See also