1
0
mirror of https://github.com/kidoman/embd synced 2024-11-10 11:38:53 +01:00
embd/samples/spi.go

49 lines
869 B
Go
Raw Normal View History

2014-05-07 19:53:29 +02:00
// +build ignore
package main
import (
"fmt"
"github.com/kidoman/embd"
_ "github.com/kidoman/embd/host/all"
)
func main() {
if err := embd.InitSPI(); err != nil {
panic(err)
}
defer embd.CloseSPI()
2014-05-21 22:49:01 +02:00
spiBus := embd.NewSPIBus(embd.SPIMode0, 0, 1000000, 8, 0)
defer spiBus.Close()
2014-05-21 23:01:42 +02:00
dataBuf := [3]uint8{1, 2, 3}
if err := spiBus.TransferAndReceiveData(dataBuf[:]); err != nil {
panic(err)
}
fmt.Println("received data is:", dataBuf)
dataReceived, err := spiBus.ReceiveData(3)
if err != nil {
panic(err)
}
fmt.Println("received data is:", dataReceived)
dataByte := byte(1)
receivedByte, err := spiBus.TransferAndReceiveByte(dataByte)
if err != nil {
panic(err)
}
fmt.Println("received byte is:", receivedByte)
receivedByte, err = spiBus.ReceiveByte()
if err != nil {
panic(err)
}
fmt.Println("received byte is:", receivedByte)
}