Skip to content

Instantly share code, notes, and snippets.

@deadprogram
Last active November 22, 2021 13:55
Show Gist options
  • Save deadprogram/06a20962dd2273f20cfcb9ebd163ada7 to your computer and use it in GitHub Desktop.
Save deadprogram/06a20962dd2273f20cfcb9ebd163ada7 to your computer and use it in GitHub Desktop.
Concept for i2c peripheral (target) interface
package main
import (
"machine"
"time"
)
var input [16]byte
func main() {
machine.I2C0.Configure(machine.I2CConfig{
// valid options are machine.I2CController or machine.I2CPeripheral
Mode: machine.I2CPeripheral,
Address: 0x84,
})
for {
if machine.I2C0.Buffered() {
n, _ := machine.I2C0.Read(input[:])
machine.I2C0.Write([]byte("hello, "))
machine.I2C0.Write(input[:n])
machine.I2C0.Write([]byte("\r\n"))
}
time.Sleep(10 * time.Millisecond)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment