2014-05-07 23:23:29 +05:30
|
|
|
// +build ignore
|
|
|
|
|
2014-04-28 01:18:14 +05:30
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/kidoman/embd"
|
|
|
|
|
|
|
|
_ "github.com/kidoman/embd/host/all"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2014-05-08 23:09:31 +05:30
|
|
|
if err := embd.InitSPI(); err != nil {
|
2014-04-28 01:18:14 +05:30
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer embd.CloseSPI()
|
|
|
|
|
2014-04-28 03:13:57 +05:30
|
|
|
spiBus := embd.NewSPIBus(embd.SpiMode0, 0, 1000000, 8, 0)
|
2014-04-28 01:18:14 +05:30
|
|
|
defer spiBus.Close()
|
|
|
|
|
2014-04-28 03:13:57 +05:30
|
|
|
dataBuf := []uint8{1, 2, 3}
|
2014-04-28 01:18:14 +05:30
|
|
|
|
2014-05-08 23:09:31 +05:30
|
|
|
if err := spiBus.TransferAndRecieveData(dataBuf); err != nil {
|
2014-04-28 01:18:14 +05:30
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2014-05-08 23:09:31 +05:30
|
|
|
fmt.Println("received data is: %v", dataBuf)
|
2014-04-28 01:18:14 +05:30
|
|
|
|
|
|
|
dataReceived, err := spiBus.ReceiveData(3)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2014-05-08 23:09:31 +05:30
|
|
|
fmt.Println("received data is: %v", dataReceived)
|
2014-04-28 01:18:14 +05:30
|
|
|
|
|
|
|
dataByte := byte(1)
|
|
|
|
receivedByte, err := spiBus.TransferAndReceiveByte(dataByte)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2014-05-08 23:09:31 +05:30
|
|
|
fmt.Println("received byte is: %v", receivedByte)
|
2014-04-28 01:18:14 +05:30
|
|
|
|
|
|
|
receivedByte, err = spiBus.ReceiveByte()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2014-05-08 23:09:31 +05:30
|
|
|
fmt.Println("received byte is: %v", receivedByte)
|
2014-04-28 01:18:14 +05:30
|
|
|
}
|