Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions itsybitsy-m4/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package main
// ItsyBitsy-M4 G <--> MPU-6050 GND
// ItsyBitsy-M4 D7 <--> MPU-6050 VCC
//
// SPI tests:
// ItsyBitsy-M4 MOSI <--> ItsyBitsy-M4 MISO
import (
"machine"
"strconv"
Expand Down Expand Up @@ -64,6 +66,7 @@ func main() {
analogReadGround()
analogReadHalfVoltage()
i2cConnection()
spiTxRx()

endTests()
}
Expand Down Expand Up @@ -277,6 +280,40 @@ func i2cConnection() {
printtestresult("pass")
}

// checks if it is possible to send/receive by spi
func spiTxRx() {
spi0 := machine.SPI0
spi0.Configure(machine.SPIConfig{
SCK: machine.SPI0_SCK_PIN,
SDO: machine.SPI0_SDO_PIN,
SDI: machine.SPI0_SDI_PIN,
Frequency: 4000000,
})

from := make([]byte, 8)
for i := range from {
from[i] = byte(i)
}
to := make([]byte, len(from))

printtest("spiTx")
err := spi0.Tx(from, to)
if err != nil {
printtestresult("fail")
} else {
printtestresult("pass")
}

printtest("spiRx")
for i := range from {
if from[i] != to[i] {
printtestresult("fail")
return
}
}
printtestresult("pass")
}

func printtest(testname string) {
print("- " + testname + " = ")
}
Expand Down