forked from espressif/arduino-esp32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCIBoardsTest.ino
45 lines (34 loc) · 1.03 KB
/
CIBoardsTest.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <Wire.h>
#include <SPI.h>
void setup() {
// UART initialization
Serial.begin(9600);
// I2C initialization
Wire.begin();
// SPI initialization
SPI.begin();
}
void loop() {
// UART echo
if (Serial.available()) {
Serial.write(Serial.read());
}
// I2C read/write
Wire.beginTransmission(0x68); // I2C address of device
Wire.write(0x00); // register to read/write
Wire.write(0xFF); // data to write (if writing)
Wire.endTransmission();
Wire.requestFrom(0x68, 1); // number of bytes to read
while (Wire.available()) {
Serial.println(Wire.read());
}
// SPI read/write
digitalWrite(SS, LOW); // select slave device
SPI.transfer(0x01); // data to write
digitalWrite(SS, HIGH); // deselect slave device
digitalWrite(SS, LOW); // select slave device
byte data = SPI.transfer(0x00); // data to read
digitalWrite(SS, HIGH); // deselect slave device
Serial.println(data);
delay(1000); // wait for 1 second before repeating loop
}