I am experimenting with the implementation of the manchester protocol for a 433 mhz transceiver. So I wrote a simple program that uses 2 pins - one for sending, another one for receiving the signal. The receiver part uses IRQ to intercept the edge change on the pin, and read its value to pass down to the manchester decoder. So far it looks good, in theory and tests, but in reality as soon as I start writing some data to the transmitter pin - the interrupt watcher on the receiver pin stops working. I use the same board for connecting the transmitter and the receiver parts.
I created some simple program to simply watch on the edge changes - and it intercepts the changes just fine, unless you use mem (wiringpi gpio) or sysfs to write a value to another pin. At this point the interrupts stop to happen.
Am I missing something?
Below is the original sample that uses GPIO 17 for reading and watching the edge change, and GPIO 21 for transmitting the signal.
package main
import (
"github.com/jdevelop/go-manchester/manchester"
"github.com/davecheney/gpio"
"fmt"
"os"
"strconv"
"time"
)
func receive(bps int) {
pin, err := gpio.OpenPin(17, gpio.ModeInput)
if err != nil {
panic(err)
}
frame := manchester.NewDataFrame()
driver := manchester.NewManchesterDriver(int64(bps), 1000000)
if err = pin.BeginWatch(gpio.EdgeBoth, func() {
driver.ReadBit(manchester.Up, time.Now().UnixNano(), func(bool) {
val := pin.Get()
println(val)
if frame.ReadBit(val) {
println("DONE")
}
})
}); err != nil {
panic(err)
}
defer pin.EndWatch()
defer pin.Close()
time.Sleep(10 * time.Second)
fmt.Println(frame)
}
func main() {
text := os.Args[2]
bps, _ := strconv.Atoi(os.Args[1])
driver := manchester.NewManchesterDriver(int64(bps), 100)
frame := manchester.BuildDataFrame([]byte(text))
pin, _ := gpio.OpenPin(21, gpio.ModeOutput)
pin.Clear()
defer pin.Close()
logger := make(chan bool, 100)
loggerF := func() {
for {
select {
case lvl := <-logger:
if lvl {
fmt.Print(1)
} else {
fmt.Print(0)
}
}
}
}
signal := func(level bool) {
if level {
pin.Set()
} else {
pin.Clear()
}
}
go loggerF()
go receive(bps)
frame.WriteFrame(func(bit bool) {
logger <- bit
driver.WriteBit(bit, signal)
})
pin.Clear()
fmt.Println()
fmt.Println("Done")
}