Bus
#struct BusAn SPI master: the pins for clock, data out, data in and chip select, the mode, the bit order and the half clock period.
| Name | Type | Description |
|---|---|---|
sck | int = 0 | The clock pin. |
mosi | int = 0 | The data out pin (master out, slave in). |
miso | int = 0 | The data in pin (master in, slave out). |
cs | int = -1 | The chip select pin, driven low while a device is selected, or -1 for none. |
mode | int = 0 | The SPI mode, 0 to 3: bit 1 is the clock level when idle, bit 0 is 0 when data is sampled on the first clock edge and 1 on the second. |
order | int = 0 | MSB_FIRST or LSB_FIRST. |
half_us | int = 0 | The time of half a clock period in microseconds, 0 for as fast as the pin functions go. |
import hw.board
import hw.spi
func main:
mut bus := spi.Open(10, 11, 12, 13, 3)
println spi.Mode(bus), board.GpioRead(10), board.GpioRead(13)
board.SimLink(11, 12)
println spi.Transfer(bus, 0x01)
spi.SetOrder(bus, spi.LSB_FIRST)
spi.SetSpeed(bus, 2)
println spi.Transfer(bus, 0x01), spi.MSB_FIRST, spi.LSB_FIRST
end3 1 1 1 1 0 1