2014-04-28 01:18:14 +05:30
|
|
|
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-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
|
|
|
|
|
|
|
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)
|
|
|
|
}
|