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
6
static
const
uint8_t dev_addr = 0x20;
8
static
const
int
sda_pin = 0;
10
static
const
int
scl_pin = 1;
11
12
uint8_t
i
= 0;
13
14
uint8_t
buffer
[32] =
"world"
;
15
16
void
onRequest
() {
17
// prewrite to buffer
18
Wire.write(
buffer
, 5);
19
20
Serial.printf(
"onRequest: %02x\n"
,
i
++);
21
}
22
23
void
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
32
void
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
41
void
loop
() {}
buffer
uint8_t buffer[32]
Definition
example_i2c.cpp:14
setup
void setup()
Definition
example_i2c.cpp:32
onReceive
void onReceive(int len)
Definition
example_i2c.cpp:23
onRequest
void onRequest()
Definition
example_i2c.cpp:16
i
uint8_t i
Definition
example_i2c.cpp:12
loop
void loop()
Definition
example_i2c.cpp:41
embedded
esp32
src
examples
example_i2c.cpp
Generated by
1.9.8