2014-05-07 19:53:29 +02:00
|
|
|
// +build ignore
|
|
|
|
|
2014-04-27 21:48:14 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/kidoman/embd"
|
|
|
|
|
|
|
|
_ "github.com/kidoman/embd/host/all"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var err error
|
|
|
|
err = embd.InitSPI()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer embd.CloseSPI()
|
|
|
|
|
2014-04-27 23:43:57 +02:00
|
|
|
spiBus := embd.NewSPIBus(embd.SpiMode0, 0, 1000000, 8, 0)
|
2014-04-27 21:48:14 +02:00
|
|
|
defer spiBus.Close()
|
|
|
|
|
2014-04-27 23:43:57 +02:00
|
|
|
dataBuf := []uint8{1, 2, 3}
|
2014-04-27 21:48:14 +02:00
|
|
|
|
|
|
|
err = spiBus.TransferAndRecieveData(dataBuf)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("Recived data is: %v", dataBuf)
|
|
|
|
|
|
|
|
dataReceived, err := spiBus.ReceiveData(3)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("Recived data is: %v", dataReceived)
|
|
|
|
|
|
|
|
dataByte := byte(1)
|
|
|
|
receivedByte, err := spiBus.TransferAndReceiveByte(dataByte)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
fmt.Println("Recived byte is: %v", receivedByte)
|
|
|
|
|
|
|
|
receivedByte, err = spiBus.ReceiveByte()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
fmt.Println("Recived byte is: %v", receivedByte)
|
|
|
|
}
|