Skip to content

Commit 90de855

Browse files
committed
boards/itsybitsy-nrf52840: add SPI rx.tx loopback test
1 parent 7a02a7c commit 90de855

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

itsybitsy-nrf52840/main.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ package main
2020
// ItsyBitsy-nRF52840 G <--> MPU-6050 GND
2121
// ItsyBitsy-nRF52840 D7 <--> MPU-6050 VCC
2222
//
23+
// SPI tests:
24+
// ItsyBitsy-nRF52840 SDO <--> ItsyBitsy-nRF52840 SDI
25+
//
2326
import (
2427
"machine"
2528
"strconv"
@@ -65,6 +68,7 @@ func main() {
6568
analogReadGround()
6669
analogReadHalfVoltage()
6770
i2cConnection()
71+
spiTxRx()
6872

6973
endTests()
7074
}
@@ -274,6 +278,41 @@ func i2cConnection() {
274278
printtestresult("pass")
275279
}
276280

281+
// checks if it is possible to send/receive by spi
282+
func spiTxRx() {
283+
spi0 := machine.SPI0
284+
spi0.Configure(machine.SPIConfig{
285+
SCK: machine.SPI0_SCK_PIN,
286+
SDO: machine.SPI0_SDO_PIN,
287+
SDI: machine.SPI0_SDI_PIN,
288+
Frequency: 4000000,
289+
})
290+
291+
from := make([]byte, 8)
292+
for i := range from {
293+
from[i] = byte(i)
294+
}
295+
to := make([]byte, len(from))
296+
297+
printtest("spiTx")
298+
err := spi0.Tx(from, to)
299+
if err != nil {
300+
printtestresult("fail")
301+
} else {
302+
printtestresult("pass")
303+
}
304+
305+
printtest("spiRx")
306+
for i := range from {
307+
if from[i] != to[i] {
308+
printtestresult("fail")
309+
return
310+
}
311+
}
312+
printtestresult("pass")
313+
}
314+
315+
277316
func printtest(testname string) {
278317
print("- " + testname + " = ")
279318
}

0 commit comments

Comments
 (0)