Note: If you have multiple gateways, all commands can also take a
--gateway option to specify which one. For brevity, that option is omitted from the below examples.
How to communicate with peripherals on the SPI bus with lager CLI¶
In order to debug hardware designs with chips that utilize an SPI bus, it's often handy to have a way of communicating with the bus directly. The Lager Gateway has a built-in SPI peripheral that you can use to communicate with your SPI chips or microcontrollers.
Install the latest version of the lager-cli tool, and confirm that you are able to communicate with your Lager Gateway.
To change the SPI mode (see https://en.wikipedia.org/wiki/Serial_Peripheral_Interface), use the --mode argument.
Currently only one hardware chip select pin works. TODO fix this.
lager-cli includes an spi read command for reading bytes from an SPI peripheral. It accepts a mandatory length argument which determines how many bytes to read.
# Read 4 bytes using mode 0 (the default) > lager spi read 4 # Read a 5-byte string from SPI using mode 1 > lager spi read --mode 1 --type string 5 # Read 3 integer bytes from SPI at 500 KHz > lager spi read --speed 500000 --type int
lager-cli includes an spi write command for writing bytes to an SPI peripheral. It accepts an arbitrary number of bytes to send.
# Write 4 bytes using mode 0 (the default) > lager spi write 0x12 0x34 0x56 0x78 # Write the string "hello" using mode 3 at 500 Khz > lager spi write --mode 3 --speed 500000 hello # Write 3 integers > lager spi write 0 127 255
lager-cli includes an spi transfer command that accepts an arbitrary number of bytes to send to an SPI peripheral, and returns the bytes that were simultaneously received.
# Write the string "hello" and return the received bytes > lager spi transfer --type string hello Lager SPI Received 5 bytes: world