我想用esp32实现iic通信中的从机,在官网找了实例代码结果编译报错。
-----------
错误信息:
sketch\sketch_aprIIC.ino.cpp.o.literal._Z5setupv+0x18): undefined reference to `TwoWire:nReceive(void (*)(int))'
sketch\sketch_aprIIC.ino.cpp.o: In function `setup()':
C:\Users\admin\Documents\Arduino\sketch_aprIIC/sketch_aprIIC.ino:22: undefined reference to `TwoWire:nReceive(void (*)(int))'
collect2.exe: error: ld returned 1 exit status
exit status 1
为开发板 ESP32 Dev Module 编译时出错。
官方代码如下
#include <Wire.h>
void setup() {
Wire.begin(8); // join i2c bus with address #8
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
}
void loop() {
delay(100);
}
// function that executes whenever data is received from master // this function is registered as an event, see setup()
void receiveEvent(int howMany) {
while (1 < Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
int x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
}