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() {
|
2014-05-08 19:39:31 +02:00
|
|
|
if err := embd.InitSPI(); err != nil {
|
2014-04-27 21:48:14 +02:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer embd.CloseSPI()
|
|
|
|
|
2014-05-21 22:49:01 +02:00
|
|
|
spiBus := embd.NewSPIBus(embd.SPIMode0, 0, 1000000, 8, 0)
|
2014-04-27 21:48:14 +02:00
|
|
|
defer spiBus.Close()
|
|
|
|
|
2014-05-21 23:01:42 +02:00
|
|
|
dataBuf := [3]uint8{1, 2, 3}
|
2014-04-27 21:48:14 +02:00
|
|
|
|
2015-12-22 18:54:33 +01:00
|
|
|
if err := spiBus.TransferAndReceiveData(dataBuf[:]); err != nil {
|
2014-04-27 21:48:14 +02:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2015-12-22 23:05:28 +01:00
|
|
|
fmt.Println("received data is:", dataBuf)
|
2014-04-27 21:48:14 +02:00
|
|
|
|
|
|
|
dataReceived, err := spiBus.ReceiveData(3)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2015-12-22 23:05:28 +01:00
|
|
|
fmt.Println("received data is:", dataReceived)
|
2014-04-27 21:48:14 +02:00
|
|
|
|
|
|
|
dataByte := byte(1)
|
|
|
|
receivedByte, err := spiBus.TransferAndReceiveByte(dataByte)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2015-12-22 23:05:28 +01:00
|
|
|
fmt.Println("received byte is:", receivedByte)
|
2014-04-27 21:48:14 +02:00
|
|
|
|
|
|
|
receivedByte, err = spiBus.ReceiveByte()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2015-12-22 23:05:28 +01:00
|
|
|
fmt.Println("received byte is:", receivedByte)
|
2014-04-27 21:48:14 +02:00
|
|
|
}
|