Page 1 of 1

M5stack undefined reference to `TwoWire::onReceive(void (*)(int))'

Posted: Mon Oct 08, 2018 3:18 am
by soujiro0725
Arduino ide 1.8.7

Hi. I am trying to establish i2c communication with M5stack.
But the following code raises an error.

Code: Select all

#include <Wire.h>
#include <M5Stack.h>

int SLAVE_ADDRESS = 0x40;

void setup() {
  // put your setup code here, to run once:
  M5.begin();
  Wire.begin(SLAVE_ADDRESS);    //set slave address
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:

  if (m5.BtnA.wasPressed()) {
    M5.Lcd.printf("hello");
  } else {
    M5.Lcd.printf("");
  }
  M5.update();

  delay(100);
}

void receiveEvent(int howMany) {
  
}
The error is

Code: Select all

Arduino:1.8.7 (Mac OS X), ボード:"M5Stack-Core-ESP32, QIO, 80MHz, Default, 921600, None"

sketch/sketch_oct04a.ino.cpp.o:(.literal._Z5setupv+0x1c): undefined reference to `TwoWire::onReceive(void (*)(int))'
sketch/sketch_oct04a.ino.cpp.o: In function `setup()':
/Users/soichi/Documents/Arduino/sketch_oct04a/sketch_oct04a.ino:33: undefined reference to `TwoWire::onReceive(void (*)(int))'
collect2: error: ld returned 1 exit status
Without "onReceive" method call, it gets compiled fine.
The code seems to have found the library, Wire.h, but "onReceive" method is the problem.

Does anyone guess why?