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

I2C works under the debugger, but not standalone?

I2C Netduino 2 Plus

  • Please log in to reply
22 replies to this topic

#1 Alex W

Alex W

    Member

  • Members
  • PipPip
  • 16 posts

Posted 08 January 2013 - 03:39 PM

I have a N+2 with the latest firmware (which I know has I2C fixes).

 

I'm using an Adafruit LSM303 compass/accelerometer module.

 

When I run my program under the Visual Studio debugger everything works great.  When I run it standalone all calls to I2CDevice.Execute return 0 bytes transferred.  Has anyone run into this?  Any ideas of how to fix it?  Even if the device was working fine under the debugger and I press the reset button (while still attached to the debugger) it will stop working.  Does the debugger somehow to a I2C reset?

 

I'm not sure if the Adafruit LSM303 has the proper pullup resistors or not (they don't publish their schematic, and on the board I just see two transistors on the SCL/SDA lines).  However since it is working while running my code under the debugger I don't think it is a pullup resistor issue. 

 

I've attached my two I2C related files.  The CompassSensor module is clearly not done and is doing things like invalid linear math for computing angles, I'm just playing around at this stage.

 

thanks,

alex

Attached Files



#2 korbai

korbai

    Member

  • Members
  • PipPip
  • 17 posts

Posted 08 January 2013 - 07:41 PM

Hello,

 

I found a very similar issue, I wrote some posts into this topic:

http://forums.netdui...-v421-update-2/

but unfortunatelly I have not got solution yet, but I found a workaround:

when I use the target devices with 5V there is no problem with I2C (PCF8574).

When I use the target devices with 3.3V, I found what you found too,

it works only under the debugger, standalone does not work.

 

My hardware works well with old Netduino, and Netduino Plus (5V and 3.3V, too).

Only the Plus 2 caused such this problem. Strange. 

 

Regards,

Zoltan



#3 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 08 January 2013 - 09:53 PM

The board looks like they have logic level converters on there with the accompanying resistors to 5v and 3.3 pullup.  I don't believe you need additional pullup resisitors for this to work properly.

 

Since I cannot see your main program loop I'm not sure if you have any delay's in there.  Sometimes the sensors need Thread.Sleep statements to allow them time to initialize and adjust.  This could be the case with this sensor which is why it works while stepping through slowly.  Also, try to see if setting the clock rate to 100mhz instead of 400mhz make a difference.  I've found a few sensors that sayd they worked up to 400mhz but worked much better at 100mhz.



#4 Alex W

Alex W

    Member

  • Members
  • PipPip
  • 16 posts

Posted 08 January 2013 - 10:28 PM

Sorry about not including my main loop.

 

I'm both sleeping for 2 seconds before the initialization and retrying the initialization when I fail.  The code looks something like this:

 

bool enabled = false;

for (int i = 0; !enabled; i++)

{

    Thread.Sleep(2000);

    oled.DrawString(0, 0, "waiting for compass... " + i.ToString());

    try

    {

        sensor = new CompassSensor();

        enabled = true;

    }

    catch (Exception e)

    {

         oled.DrawString(0, 1, "e: " + e.ToString());

    }

}

 

oled is a SPI device, not I2C and I'm using it for debugging purposes right now.

 

When I run this not under the debugger the device will slowly count to infinity showing the exception that is thrown in I2CBus.cs.

 

When I get home I'll try korbai's solution of using 5v for the sensor instead of 3.3v.  Based on the thread that he linked to it looks like he was seeing exactly the same issue.  It's a weird bug.



#5 Alex W

Alex W

    Member

  • Members
  • PipPip
  • 16 posts

Posted 08 January 2013 - 10:33 PM

Also, stepping is not necessary to make it work.  Running under the debugger (pressing f5 in VS to deploy and run) allows it to work.  Running the same program via device reset or removing and adding back power won't allow it to work.

 

I know that just running on the debugger can have subtle changes to timing and suspected a timing issue, but my retry loop (and longer delays that I've tried) should solve that issue.

 

alex



#6 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 08 January 2013 - 10:49 PM

Sorry about not including my main loop.

 

I'm both sleeping for 2 seconds before the initialization and retrying the initialization when I fail.  The code looks something like this:

 

bool enabled = false;

for (int i = 0; !enabled; i++)

{

    Thread.Sleep(2000);

    oled.DrawString(0, 0, "waiting for compass... " + i.ToString());

    try

    {

        sensor = new CompassSensor();

        enabled = true;

    }

    catch (Exception e)

    {

         oled.DrawString(0, 1, "e: " + e.ToString());

    }

}

 

oled is a SPI device, not I2C and I'm using it for debugging purposes right now.

 

When I run this not under the debugger the device will slowly count to infinity showing the exception that is thrown in I2CBus.cs.

 

When I get home I'll try korbai's solution of using 5v for the sensor instead of 3.3v.  Based on the thread that he linked to it looks like he was seeing exactly the same issue.  It's a weird bug.

According to the design of that breakout board, it takes 5V and has an on board 3.3v regulator.  It does need to be powered by 5V.



#7 Alex W

Alex W

    Member

  • Members
  • PipPip
  • 16 posts

Posted 09 January 2013 - 12:27 AM

Where did you see that?  The Adafruit page says "Since it's a 3.3V max chip, we added circuitry to make it 5V-safe logic and power, for easy use with either 3 or 5V microcontrollers. Simply connect VCC to +3-5V and ground to ground."

 

This is the device that I'm using:

http://www.adafruit.com/products/1120

 

The chip data page says that it wants 2.5V to 3.3V.  It looks like previous versions of this chip required 3.3V and 1.8V, but the one used by Adafruit doesn't.



#8 Alex W

Alex W

    Member

  • Members
  • PipPip
  • 16 posts

Posted 09 January 2013 - 01:13 AM

I tried powering the Vin from 5v or using the direct 3.3v hookup (that appears to bypass the onboard regulator) and it doesn't seem to matter.  The device works fine when I run under the debugger with no breakpoints or stepping, but doesn't work when run standalone.

 

Chris Walker?  If you have one of these devices I'd be happy to write a <20 line repro module.



#9 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 09 January 2013 - 02:18 AM

Hi Alex, Do you have a logic analyzer by any chance? What would really help is to see what is going on from an I/O perspective. A 20-line repro would be very, very useful :) Chris

#10 Alex W

Alex W

    Member

  • Members
  • PipPip
  • 16 posts

Posted 09 January 2013 - 03:46 AM

I don't have a logic analyzer.  I'm a software guy who is dusting off some old skills and playing with hardware.  I've been wanting to play with these devices for a long time and finally came up with a useful application.

 

I've attached a demo program that repros the bug for me and uses nothing but the LED for output.

 

The good news is that if we can solve this problem then I have a full demonstration program for the LSM303 working that returns both heading and angles in all three axis.  I couldn't find any other Netduino examples with this device.

Attached Files



#11 Alex W

Alex W

    Member

  • Members
  • PipPip
  • 16 posts

Posted 09 January 2013 - 10:43 PM

With 4.2.2.0 this fails every time, not only when running standalone...

 

I went back to 4.2.1.2 without reverting my SDK DLLs and it works again under the debugger (but still not standalone).  It must be a timing issue with this device and the libraries.  I'd be interested in recommendations for a known working compass/tilt chip (and would prefer to have a single device instead of two).

 

alex



#12 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 09 January 2013 - 03:52 AM

Hi Alex, Okay, very interesting. We're going to pull this chip into the lab after next week's 4.2.2 SDK launch. We actually work with this family of ST MEMS chips already. It'll take a few days to build a breakout for the chip and Netduino Plus 2. We're also ordering one of Adafruit's breakouts. I may be pinging you for a bit more info about your wiring setup. The new firmware resets the power during deployment, so we should be at a known-good state (and not "warmed up from before"). Chris

#13 Alex W

Alex W

    Member

  • Members
  • PipPip
  • 16 posts

Posted 10 January 2013 - 04:08 PM

Thanks, I look forward to your findings.

 

Wiring is straightforward:

 

Netduino :: Adafruit LMS303 breakout board

5V :: Vin

Gnd :: Gnd

SC :: SCL

SD :: SDA

 

3.3v (this is regulated output from their onboard regulator), drdy, i1, and i2 pins on the breakout board aren't used.



#14 Alex W

Alex W

    Member

  • Members
  • PipPip
  • 16 posts

Posted 10 January 2013 - 05:49 PM

A working driver that outputs heading, pitch, and roll is attached (but of course it currently only works when running under the debugger).

 

Attached Files



#15 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 10 January 2013 - 06:39 PM

Alex, If you power the breakout via 3.3V instead of 5V, does that change anything? Do you happen to have a schematic for the breakout? I couldn't find one. And I2C level conversion chips can be a bit tricky...which I believe are being used here. Chris

#16 Alex W

Alex W

    Member

  • Members
  • PipPip
  • 16 posts

Posted 10 January 2013 - 09:03 PM

No, I have the same failure using 3.3V as 5V.  I've tried it both ways.

 

I don't have a schematic for the breakout board that I'm using, Adafruit doesn't appear to publish one.  Had I known better a week ago I'd have ordered this board:

http://www.pololu.co...og/product/2124

 

They have much better documentation and do publish the schematics.  Their schematic is here:

http://www.pololu.co...ure/view/0J4051

 

From board inspection it looks like Adafruit uses a similar schematic.  The Adafruit board is using 10k pullup resistors (instead of 4.7k) and uses a single capacitor to handle noise on Vin instead of the 4 on the Pololu board.  I don't have a meter that allows me to measure the capacitance values to see if they match on the two boards.



#17 Alex W

Alex W

    Member

  • Members
  • PipPip
  • 16 posts

Posted 23 January 2013 - 06:37 PM

Chris: Any updates on this?  I've seen a few other I2C threads pop by too.

 

In the meantime I've ordered a Netduino 1 (a couple of days before the Netduino 2 announcement) and the I2C on there is working just fine with this device.  I won't be able to test this soon on my Netduino Plus 2 because it will be secured away into device.



#18 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 23 January 2013 - 08:52 PM

Hi Alex, We ordered a few different versions of this breakout to do an analysis. We should have them all by next week. We're working on a small update for Netduino 2 and Netduino Plus 2, but we can slip this into our test queue right after that. I've been following the I2C threads and it seems like things are working well from a software perspective. There were some hacks with Netduino gen1 that were required (such as for repeated start bit). That tripped things up a bit for users upgrading to Netduino gen2 (which shouldn't need those hacks). Overall it seems like most scenarios and hardware are working well...now we're digging in to help provide guidance on the other 1% :) Chris

#19 Alex W

Alex W

    Member

  • Members
  • PipPip
  • 16 posts

Posted 15 April 2013 - 03:28 AM

Chris:

 

Did Netduino ever test this with a logic analyzer?

 

I'm back in the position of wanting to use this device with a N2P and was hoping to hear the good news that you fixed the I2C bug here.



#20 Jon Henry

Jon Henry

    Advanced Member

  • Members
  • PipPipPip
  • 43 posts

Posted 16 April 2013 - 03:59 AM

Hi Alex. I use the MinIMU-V2 from Polulu which uses the LSM303DLHC chip as well as a L3Gd20 Gyro. I run this board along with a Lassen LS20031 GPS and BMP085 with no issues. I run my I2C bus at 100kHz. You shouldnt have to sleep for anything on the LSM303 board.

 

I had what I thought were I2C issues when I switched to the N+2 but it turned out to be buffer overrun issues with the UART. Once I handled that, my I2C ran flawlessly on 4.2.2.0. I also switched from the I2C code you are using to the toolbox.NETMF multiI2C class and have found much fewer hiccups.

 

As far as pullups go, I did have to add 880 Ohm pullups to get under 300ns even with both my MinIMU-V2 and BMP085 boards having onboard pullups. I was at about 340ns, which worked but did hiccup now and then. Ive had the board spitting out data continuously for three days now with no hiccups with the extra pullups.







Also tagged with one or more of these keywords: I2C, Netduino 2 Plus

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.