ND+2 with I2C problems? Can't get any responses from slaves - Netduino Plus 2 (and Netduino Plus 1) - Netduino Forums
   
Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

ND+2 with I2C problems? Can't get any responses from slaves

ND+2 I2C IIC VB2010 Need Help

  • Please log in to reply
3 replies to this topic

#1 MATTHEWPENA

MATTHEWPENA

    New Member

  • Members
  • Pip
  • 3 posts

Posted 17 April 2015 - 04:49 AM

Hello, I need help or direction on how to get an I2C device working with my ND+2.  I have tried many things and searched the forums for answers but nothing seems to work!  Am I doing something horibbly wrong or is there still somekind of hardware, firmware or software problems i don't know about?  is there a known good setup/combination of firmware/hardware/software/drivers that works?  it should be simple!

i've tried direct write/reads, combo write/reads...and today I tried the MultiI2C in the MFtoolbox...still no response from the I2C slave devices.

 

here is my VB code...

 

Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports Microsoft.SPOT.Hardware.I2CDevice
Imports SecretLabs.NETMF.Hardware
Imports SecretLabs.NETMF.Hardware.Netduino
Imports Toolbox.NETMF.Hardware
Imports Toolbox.NETMF.Hardware.MultiI2C
Imports Toolbox.NETMF.Tools
 
Module Module1
    'ND+2 program ... M.Peña, April 2015
    'Firmware is 4.2.2.2, NetMF is 4.2, VB 2010 Express
 
    'trying to get the I2C to work!
 
    Sub Main()
 
        'using LSM303DLM 3-axis accelerometer, 3-axis magnetometer
        'accel: 8-bit write addr = 00110000b = 30h = 48d
        'mag  : 8-bit write addr = 00111100b = 3Ch = 60d
        'the carrier board has pull-ups on the SDA & SCL lines
 
        'whoami @ 0Fh, should read 00111100b = 3Ch = 60d
 
        'using the SDA pin toggle to wake up I2C ?
        Dim p As New Microsoft.SPOT.Hardware.OutputPort_        (SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_SDA, True)
        p.Write(False)
        System.Threading.Thread.Sleep(10)
        p.Dispose()
        p = Nothing
        System.Threading.Thread.Sleep(2000)
        Debug.Print("pulled SDA lo")
        System.Threading.Thread.Sleep(2000)
 
        'set up I2C with mag's write addr 3Ch & 100kHz clock
        Dim myiic As New MultiI2C(&H3C, 100)
        Dim retval As Int32 = -1
        Dim REGADDR() As Byte = {&HF}                'who am I reg
        Dim buff(0) As Byte                                       'buffer byte for returned data
 
        retval = myiic.WriteRead(REGADDR, buff)     'write reg addr & read into buff from reg addr
 
        'always returns 0 and 0!
        Debug.Print("ret val  = " & retval.ToString)
        Debug.Print("buff data = " & buff(0).ToString)
 
 
        System.Threading.Thread.Sleep(10000)
 
 
 
    End Sub
 
I really hope someone can direct me in the right direction...Thank You all
Matthew


#2 KiwiDev

KiwiDev

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts
  • LocationNew Zealand

Posted 19 April 2015 - 09:36 AM

Hi Matthew,

 

Assuming your pull-up resistors are good, I think it might be your addressing. See this blog post for more info

 

I checked the Arduino driver code 

 

#define Magnetometer  0x1E  // assuming SA0 grounded
#define Accelerometer  0x18  // assuming SA0 grounded
 
Sorry my code sample is C# my vb skills are a bit rusty. I have also used the built in I2C functionality without a wrapper to keep dependencies to a minimum.
 
 
public static void Main()
{
   using (OutputPort i2cPort = new OutputPort(Pins.GPIO_PIN_SDA, true))
   {
      i2cPort.Write(false);
      Thread.Sleep(1000);
   }
 
   using (I2CDevice device = new I2CDevice(new I2CDevice.Configuration(, 100)))
   {
      byte[] writeBuffer = { 0x0F};
      byte[] readBuffer = new byte[1];
 
      // check that sensor connected by reading who am i 
      I2CDevice.I2CTransaction[] action = new I2CDevice.I2CTransaction[] 
      { 
         I2CDevice.CreateWriteTransaction(writeBuffer),
         I2CDevice.CreateReadTransaction(readBuffer)
      };
 
      int length = device.Execute(action, 200 );
      Debug.Print("Byte count " + length.ToString());
      foreach (byte Byte in readBuffer)
      {
         Debug.Print(Byte.ToString());
      }
   }
}

 

I have loaned my LM303 breakout to a friend so working from memory.

 

@KiwiBryn
blog.devmobile.co.nz


#3 MATTHEWPENA

MATTHEWPENA

    New Member

  • Members
  • Pip
  • 3 posts

Posted 20 April 2015 - 12:50 AM

Hi Kiwi, Thanks for the reply.  I have tried those addresses, but still no no response.  I've tried looping thru all the speeds from 10khz to 400khz...the board has 4.7 k pull-ups on the lines.  I've done direct commands as well...one write and one read and a combined write/read...still all zero's for return value and return byte!  I just don't have any confirmation that the hardware/firmware/software that I'm using will work.  I have tried the netduino and netduinoplus for hardware references...neither make a difference in getting it to work.  I have 4.2.2.2 firmware and 4.2 netmf drivers for windows 7-64.   I sure wish the I2C doc's spelled out what the commands actually do in code in regards to addresses and set bits.

I have gotten an ultrasonic unit working, xbee units working, a GPS and motor controllers working for my robot...but not this SIMPLE I2C CONNECTION...I Just need to get a real-time heading!  I couldn't locate an analog-output magnetometer...I got an analog accelerometer working, but that dosn't give me a heading!  Any other ideas, hints, tips, tricks would be greatly appreciated...this one's really stumping me and pissing me off a bit too!  I will breakout my old O-scope to check the lines, but if they are working, then what else can the problem be?  I have checked and replaced my jumpers to the board and checked the voltage levels...all OK there.

thanks again everyone.

Matthew



#4 MATTHEWPENA

MATTHEWPENA

    New Member

  • Members
  • Pip
  • 3 posts

Posted 20 April 2015 - 04:19 AM

I finally got some reading from the unit....hurray!  I did have to use base address &h1E and not &h3C.  I'm only running at 10kHz.  Not sure what i did to get it going this time as I had tried the 1E address before.  I hooked up my O-scope for testing today and changed the program (which uses direct I2C commands, and not the multiI2C ones) to just run at 10kHz and read the whoami register in a loop.  It started working and I got return values from the transactions and the 3C value from the whoami register!  go figure?  Next, I set out to read the mag registers...but the auto increment thing didn't seem to work...However, i then tried writting each address before the read...and I started getting real values from all 6 registers that actually change when I move my board! woo hoo!  Now i just have to figure out the proper way to but the bytes together for a full x, y & z values!  i'm not exactly sure how to do that...and I havn't seen any VB code to do it...only C++ or C#, which is only a little helpful.  I'll propably figure it out, but again, any help would be appreciated.  thanks all.

Matthew







Also tagged with one or more of these keywords: ND+2, I2C, IIC, VB2010, Need Help

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.