Neo Basic M4 I2C detect

Discussion in 'UDOO NEO' started by Gary Huband, Sep 8, 2016.

  1. Gary Huband

    Gary Huband New Member

    Joined:
    Aug 1, 2016
    Messages:
    22
    Likes Received:
    7
    The below code to detect I2C devices (MCP3424 ADC) on arduino like micro-controllers works perfectly on an Arduino Uno R3 and a Teensy 3.2, but when run on the M4 shows that all addresses have a device connected. Why doesn't this work on the Neo? Do I need to do some special setup on the Neo (hardware and/or software)? I can successfully read the MCP3424 from the M4 when connected to I2C2 on the Neo.

    Thanks in advance.

    The code is from Steve Marple's github MCP342X library.
    Code:
    #include <Wire.h>
    
    void setup(void)
    {
      Serial.begin(115200);
      Wire.begin();
      Serial.println("The MCP3422 and MCP3426 use I2C address 0x68, all other devices can be");
      Serial.println("configured to use any address in the range 0x68 - 0x6F (inclusive).");
      Serial.println("Be aware that the DS1307 uses address 0x68.");
      Serial.println();
      for (uint8_t add = 0X68; add < 0X6F; add++) {
        //Serial.print("Trying ");
        //Serial.println(add);
        Wire.requestFrom(add, (uint8_t)1);
        if (Wire.available()) {
          Serial.print("Found device at: 0x");
          Serial.println(add, HEX);
        }
      }
      Serial.println("Done");
    }
    
    void loop(void)
    {
      ;
    }
    
     
    Last edited by a moderator: Sep 16, 2016
  2. ektor5

    ektor5 Administrator Staff Member

    Joined:
    Jul 1, 2013
    Messages:
    97
    Likes Received:
    48
    Hi there Gary,
    If you are using SCL/SDA pins, maybe you better use Wire1 instead of Wire.

    Let me know,
    Ek5
     
  3. Gary Huband

    Gary Huband New Member

    Joined:
    Aug 1, 2016
    Messages:
    22
    Likes Received:
    7
    No, Wire1 did not work.
     
  4. ektor5

    ektor5 Administrator Staff Member

    Joined:
    Jul 1, 2013
    Messages:
    97
    Likes Received:
    48
    If you use Wire, you'll talk with the Brick Connector, that is connected also with A9. If you've also enabled the i2c on A9 via Device Tree Editor, you'll have 2 master devices on the same bus. This will result in a faulty behavior.
     
  5. Gary Huband

    Gary Huband New Member

    Joined:
    Aug 1, 2016
    Messages:
    22
    Likes Received:
    7
    The Neo Doc under Arduino M4 Processor, Arduino differences says:

    UDOO Neo M4 Processor has 2 I2C buses wired to the pinout headers and consequentially have 2 Wire objects:

    • Wire: on Brick Connector
    • Wire1: on SCL SDA pins
    Be careful and double check when calling Wire.begin() or Wire1.begin() in sketches or libraries. Also check out to have I2C-2 disabled on A9 if you use Wire.

    So to use the I2C on the M4 I have to:
    - Remove I2C-2 from the bricks connector using the Device Tree Editor (the linux side will not have access to I2C-2)
    - Reboot
    - If I use SCL and SDA on the Arduino header then I should always use Wire1.
    - If I want to access the bricks connector from the M4 then I use Wire.

    Is this correct?
    Can someone post example code for reading an I2C device from the M4?

    Thanks
     
    Last edited: Sep 28, 2016

Share This Page