Serial Peripheral Interface Bus - Wikipedia, the free encyclopedia
https://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus
U-boot SPI test tool
The u-boot command sspi Usage:
sspi - SPI utility command
Usage:
sspi [<bus>:]<cs>[.<mode>] <bit_len> <dout> - Send and receive bits
<bus> - Identifies the SPI bus
<cs> - Identifies the chip select
<mode> - Identifies the SPI mode to use
<bit_len> - Number of bits to send (base 10)
<dout> - Hexadecimal string that gets sent
<dout> is in hex but without the prefix "0x". All others are in decimal.
The following is SPI mode defined in u-boot/include/spi.h. But still depends on the mode that SPI controller/driver can handle:
/* SPI mode flags */It depends on the requirement of the device, as well as the data sent to the device as command. Says we require bus=0, CS=2, data len=32, data=0x51525354, the device require SPI_3WIRE, SPI_CPHA, SPI_CPOL=> mode=0x13 (19).
#define SPI_CPHA 0x01 /* clock phase */
#define SPI_CPOL 0x02 /* clock polarity */
#define SPI_MODE_0 (0|0) /* (original MicroWire) */
#define SPI_MODE_1 (0|SPI_CPHA)
#define SPI_MODE_2 (SPI_CPOL|0)
#define SPI_MODE_3 (SPI_CPOL|SPI_CPHA)
#define SPI_CS_HIGH 0x04 /* CS active high */
#define SPI_LSB_FIRST 0x08 /* per-word bits-on-wire */
#define SPI_3WIRE 0x10 /* SI/SO signals shared */
#define SPI_LOOP 0x20 /* loopback mode */
#define SPI_SLAVE 0x40 /* slave mode */
#define SPI_PREAMBLE 0x80 /* Skip preamble bytes */
# sspi 0:2.19 32 51525354
51525354
Linux SPI test tool
Projet spi-tools « Christophe Blaess
http://www.blaess.fr/christophe/2014/08/12/projet-spi-tools/
https://github.com/cpb-/spi-tools
usage: ./spi-config options...CPOL=1, idle state is high
options:
-d --device= use the given spi-dev character device.
-q --query print the current configuration.
-m --mode=[0-3] use the selected spi mode.
0: low iddle level, sample on leading edge
1: low iddle level, sample on trailing edge
2: high iddle level, sample on leading edge
3: high iddle level, sample on trailing edge
-l --lsb={0,1} LSB first (1) or MSB first (0)
-b --bits=[7...] bits per word
-s --speed= set the speed in Hz
-h --help this screen
-v --version display the version number
CPHA=1, sample on falling
=>mode=3
But there's no 3WIRE related config, and don't know how to decide speed and lsb option.
spi-config -d /dev/spidev0.0 -m 3 -l 0 -b 8
spi-config -d /dev/spidev0.0 -q
沒有留言:
張貼留言