mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-16 21:03:23 +00:00
sx127x: lora rx/tx example working, now assumes pybadge+featherwing
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
// This example code demonstrates Lora RX/TX With SX127x driver
|
// This example code demonstrates Lora RX/TX With SX127x driver
|
||||||
// You need to connect SPI, DIO0 and DIO1 to use.
|
// You need to connect SPI, RST, CS, DIO0 (aka IRQ) and DIO1 to use.
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"machine"
|
"machine"
|
||||||
@@ -22,11 +22,11 @@ var (
|
|||||||
loraRadio *sx127x.Device
|
loraRadio *sx127x.Device
|
||||||
txmsg = []byte("Hello TinyGO")
|
txmsg = []byte("Hello TinyGO")
|
||||||
|
|
||||||
// We assume the module is connected this way:
|
// We assume LoRa Featherwing module is connected to PyBadge:
|
||||||
SX127X_PIN_RST = machine.PB9
|
SX127X_PIN_RST = machine.D11
|
||||||
SX127X_PIN_CS = machine.PB8
|
SX127X_PIN_CS = machine.D10
|
||||||
SX127X_PIN_DIO0 = machine.PA0
|
SX127X_PIN_DIO0 = machine.D6
|
||||||
SX127X_PIN_DIO1 = machine.PA1
|
SX127X_PIN_DIO1 = machine.D9
|
||||||
SX127X_SPI = machine.SPI0
|
SX127X_SPI = machine.SPI0
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -35,6 +35,7 @@ func dioIrqHandler(machine.Pin) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
println("\n# TinyGo Lora RX/TX test")
|
println("\n# TinyGo Lora RX/TX test")
|
||||||
println("# ----------------------")
|
println("# ----------------------")
|
||||||
machine.LED.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
machine.LED.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
@@ -85,7 +86,7 @@ func main() {
|
|||||||
tStart := time.Now()
|
tStart := time.Now()
|
||||||
|
|
||||||
println("main: Receiving Lora for 10 seconds")
|
println("main: Receiving Lora for 10 seconds")
|
||||||
for int(time.Now().Sub(tStart).Seconds()) < 10 {
|
for time.Since(tStart) < 10*time.Second {
|
||||||
buf, err := loraRadio.LoraRx(LORA_DEFAULT_RXTIMEOUT_MS)
|
buf, err := loraRadio.LoraRx(LORA_DEFAULT_RXTIMEOUT_MS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
println("RX Error: ", err)
|
println("RX Error: ", err)
|
||||||
|
|||||||
@@ -31,22 +31,6 @@ const (
|
|||||||
RFSWITCH_TX_HP = iota
|
RFSWITCH_TX_HP = iota
|
||||||
)
|
)
|
||||||
|
|
||||||
// const (
|
|
||||||
// RadioEventRxDone = iota
|
|
||||||
// RadioEventTxDone = iota
|
|
||||||
// RadioEventTimeout = iota
|
|
||||||
// RadioEventWatchdog = iota
|
|
||||||
// RadioEventCrcError = iota
|
|
||||||
// RadioEventUnhandled = iota
|
|
||||||
// )
|
|
||||||
|
|
||||||
// // RadioEvent are used for communicating in the radio Event Channel
|
|
||||||
// type RadioEvent struct {
|
|
||||||
// EventType int
|
|
||||||
// IRQStatus uint16
|
|
||||||
// EventData []byte
|
|
||||||
// }
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PERIOD_PER_SEC = (uint32)(1000000 / 15.625) // SX1261 DS 13.1.4
|
PERIOD_PER_SEC = (uint32)(1000000 / 15.625) // SX1261 DS 13.1.4
|
||||||
SPI_BUFFER_SIZE = 256
|
SPI_BUFFER_SIZE = 256
|
||||||
|
|||||||
Reference in New Issue
Block a user