🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Troubles with serial connection between Core2 and AtomMatrix

    Core 2
    2
    2
    1.8k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      HappyUser
      last edited by

      Wow, this should have been simple but apparently I am overseeing something.
      I have a M5Stack Core 2 connected to M5AtomMatrix using the Port A on Core 2 and HY2.0-4P port on the Matrix. Included the code of sender and receiver. But I dont see any transmission going on. Which obvious mistake am I making here?
      M5Stack Core 2 code :

      #include <M5Core2.h>
      #include <Wire.h>
      #define I2C_DEV_ADDR 0x55
      uint32_t i = 0;

      void setup() {

      M5.begin(true, true, true, true);
      delay(300);
      
      Serial.setDebugOutput(true);
      Wire.begin(32,33);  // SDA SCL M5Stack Core 2
      

      }

      void loop() {
      delay(5000);

      //Write message to the slave
      Wire.beginTransmission(I2C_DEV_ADDR);
      Wire.printf("Hello World! %u", i++);
      uint8_t error = Wire.endTransmission(true);
      Serial.printf("endTransmission: %u\n", error);

      //Read 16 bytes from the slave
      error = Wire.requestFrom(I2C_DEV_ADDR, 16);
      Serial.printf("requestFrom: %u\n", error);
      if(error){
      uint8_t temp[error];
      Wire.readBytes(temp, error);
      log_print_buf(temp, error);
      }

      }

      M5Atom Matrix code here:

      //#include "M5Atom.h"
      #include "M5StickC.h"
      #include <Wire.h>
      #define I2C_DEV_ADDR 0x55

      uint32_t i = 0;

      void onRequest(){
      Wire.print(i++);
      Wire.print(" Packets.");
      Serial.println("onRequest");
      }

      void onReceive(int len){
      Serial.printf("onReceive[%d]: ", len);
      while(Wire.available()){
      Serial.write(Wire.read());
      }
      Serial.println();
      }

      void setup() {

      M5.begin(true,true,true);
      delay(300);
      

      Serial.begin(115200);
      Serial.setDebugOutput(true);
      Wire.onReceive(onReceive);
      Wire.onRequest(onRequest);
      Wire.begin(26,32); // SDA SCL M5Atom

      }

      void loop() {

      }

      1 Reply Last reply Reply Quote 0
      • felmueF
        felmue
        last edited by

        Hello @HappyUser

        you are so close. Right now you are setting up both devices as I2C masters. However M5Atom needs to be an I2C slave. To do this the first parameter of Wire.begin() needs to be the slave address. Try this:

        Wire.begin((uint8_t)I2C_DEV_ADDR, 26, 32);
        

        Thanks
        Felix

        GPIO translation table M5Stack / M5Core2
        Information about various M5Stack products.
        Code examples

        1 Reply Last reply Reply Quote 0
        • First post
          Last post