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

    M5Dial external i2C (port A) with Arduino Wire

    Scheduled Pinned Locked Moved Arduino
    4 Posts 2 Posters 2.4k Views
    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.
    • M Offline
      minieigi
      last edited by

      I want to use a I2C CAN Bus Module https://docs.longan-labs.cc/1030017/ connected to the port A on the M5Dial.
      The Longan_I2C_CAN_Arduino lib uses the Arduino Wire lib.
      I get the following error probably because It uses the internal I2C.

      Guru Meditation Error: Core  1 panic'ed (IllegalInstruction). Exception was unhandled.
      Memory dump at 0x4200f55c: e2e502ad 000000ff fd004136
      ...
      

      in the main.ino file I declare a second Wire instance and initialize it with the pins used on the M5Dial.

      TwoWire i2Ctwo(2);
      I2C_CAN CAN(0x25, &i2Ctwo); // Set I2C address and Wire instance 
      
      void setup() {
        int8_t SDA_2 = M5.Ex_I2C.getSDA(); // 2 (G13)
        int8_t SCL_2 = M5.Ex_I2C.getSCL(); // 3 (G15)
        i2Ctwo.begin(SDA_2, SCL_2);
      ...
      

      But the M5Dial class uses already the I2C_Class instead of the TwoWire class.

      // for external I2C device (Port.A)
         I2C_Class &Ex_I2C = m5::Ex_I2C;
      

      I modified the I2C_CAN lib to be able to pass a TwoWire * pointer.

      I2C_CAN::I2C_CAN(unsigned char __addr, TwoWire *__i2c = &Wire)
      {
          IIC_ADDR = __addr;
          i2C = __i2c;
      }
      
      void I2C_CAN::begin()
      {
          i2C->begin();
      }
      
      void I2C_CAN::IIC_CAN_SetReg(unsigned char __reg, unsigned char __len, unsigned char *__dta)
      {
          i2C->beginTransmission(IIC_ADDR);
          i2C->write(__reg);
          for(int i=0; i<__len; i++)
          {
              i2C->write(__dta[i]);
          }
          i2C->endTransmission();
      }
      ...
      

      Has anyone tried to use a I2C extension on port A with a standard Arduino lib? Any help would be appreciated.

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

        Hello @minieigi

        have you tried to simply use Wire? E.g.

        //  i2Ctwo.begin(SDA_2, SCL_2);
          Wire.begin(SDA_2, SCL_2);
        

        In addition you could also try to first release/end the predefined Wire:

          M5.Ex_I2C.release();
        

        Thanks
        Felix

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

        1 Reply Last reply Reply Quote 0
        • M Offline
          minieigi
          last edited by

          If I leave the Longan_I2C_CAN_Arduino lib unchanged I get one CAN message before the device reboots and I see the error I posted above.
          It seems the standard Wire pins are configured properly.
          If I add Wire.begin(2, 3) the device is not even starting Serial debug.
          M5.Ex_I2C.release(); is not making any difference.

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

            Hello @minieigi

            you are correct, the standard Wire pins are configured correctly for port A, but in your case you don't want the I2C_Class wrapper from M5Unified. So the idea is to release/end Wire as it has been initialized in M5.begin() and then restart Wire by calling Wire.begin(13, 15).

            And yes, I think the release() is done automatically when Wire is re-initialize.

            Note: I don't have this particular sensor so I cannot fully test this myself.

            Thanks
            Felix

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

            1 Reply Last reply Reply Quote 0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • First post
              Last post