-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
46 lines (35 loc) · 968 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright 2019 Michal Derkacz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// SPI loop test: wire PB14 and PB15 together.
package main
import (
"time"
"github.com/embeddedgo/stm32/hal/gpio"
"github.com/embeddedgo/stm32/hal/spi"
"github.com/embeddedgo/stm32/hal/spi/spi2"
_ "github.com/embeddedgo/stm32/devboard/f4-discovery/board/system"
)
func main() {
// Allocate GPIO pins
pb := gpio.PB()
pb.EnableClock(true)
sck := pb.Pin(13)
miso := pb.Pin(14)
mosi := pb.Pin(15)
// Configure SPI pins
sd := spi2.Driver()
sd.UsePinMaster(sck, spi.SCK)
sd.UsePinMaster(mosi, spi.MOSI)
sd.UsePinMaster(miso, spi.MISO)
// Configure and enable SPI
sd.Setup(spi.Master|spi.SoftSS|spi.ISSHigh, 1e6)
sd.SetWordSize(8)
sd.Enable()
var buf [40]byte
for i := 0; ; i++ {
sd.WriteStringRead("Hello world!", buf[:])
println(string(buf[:]))
time.Sleep(time.Second)
}
}