ENTS-tock
Environmental NeTworked Sensor firmware on Tock OS
Loading...
Searching...
No Matches
example_i2c.cpp
Go to the documentation of this file.
1#include <Arduino.h>
2
3#include "Wire.h"
4
6static const uint8_t dev_addr = 0x20;
8static const int sda_pin = 0;
10static const int scl_pin = 1;
11
12uint8_t i = 0;
13
14uint8_t buffer[32] = "world";
15
16void onRequest() {
17 // prewrite to buffer
18 Wire.write(buffer, 5);
19
20 Serial.printf("onRequest: %02x\n", i++);
21}
22
23void onReceive(int len) {
24 Serial.printf("onReceive[%d]: ", len);
25
26 while (Wire.available()) {
27 Serial.write(Wire.read());
28 }
29 Serial.println();
30}
31
32void setup() {
33 Serial.begin(115200);
34
35 Wire.onReceive(onReceive);
36 Wire.onRequest(onRequest);
37
38 Wire.begin(dev_addr, sda_pin, scl_pin, 400000);
39}
40
41void loop() {}
uint8_t buffer[32]
void setup()
void onReceive(int len)
void onRequest()
uint8_t i
void loop()