{
Int ret.
Int mode=SPI_MODE_3;
Int bits=8;
Double speed=133000000;
Int fd.
Fd=open ("/dev/spidev0.0 O_RDWR);
If (fd & lt; 0)
Printf (" open spidev0.0 failed \ n ");
The else
Printf (" open spidev0.0 success \ n ");
Ret=ioctl (fd, SPI_IOC_WR_MODE, & amp; Mode);
If (ret & lt; 0)
Printf (" always set a spi mode \ n ");
The else
Printf (" set spi mode success \ n ");
Ret=ioctl (fd, SPI_IOC_WR_BITS_PER_WORD, & amp; Bits);
If (ret & lt; 0)
Printf (" always set bits per word \ n ");
The ioctl (fd, SPI_IOC_WR_MAX_SPEED_HZ, & amp; Speed);
If (ret & lt; 0)
Printf (" always set a Max speed hz \ n ");
Char tx_buf [4].
Char rx_buf [4]={0 x00 to 0 x00 to 0 x00 to 0 x00};
Tx_buf [0]=0 x90;
Tx_buf [1]=0 x00;
Tx_buf [2]=0 x00;
Tx_buf [3]=0 x00;
Struct spi_ioc_transfer xfer;
Memset (& amp; Xfer, 0, sizeof (xfer));
Xfer. Tx_buf=tx_buf;
Xfer. Rx_buf=rx_buf;
Xfer. Len=4;
Xfer. Speed_hz=speed;
Xfer. Bits_per_word=bits;
Ret=ioctl (fd, SPI_IOC_MESSAGE (1), & amp; Xfer);
Printf (" ioctl ret: % d \ n ", ret);
Printf (" 0 x % x \ n ", rx_buf [0]).
Printf (" 0 x % x \ n ", rx_buf [1]).
Printf (" 0 x % x \ n ", rx_buf [2]).
Printf (" 0 x % x \ n ", rx_buf [3]).
Close (fd);
return 0;
}
CodePudding user response:
Help, the great god to help me, have no experience