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

soujiro0725
Posts: 1
Joined: Mon Oct 08, 2018 3:12 am

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

Postby soujiro0725 » Mon Oct 08, 2018 3:18 am

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?

Who is online

Users browsing this forum: No registered users and 85 guests