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

Netduino Plus 2 - I2C not working


  • Please log in to reply
38 replies to this topic

#21 egeorgiou

egeorgiou

    Member

  • Members
  • PipPip
  • 28 posts
  • LocationLondon - United Kingdom

Posted 30 November 2012 - 10:02 PM

Hi egeorgiou,


Hmm, very interesting. A few things:

1. Do you have a logic analyzer by any chance? If you do, it would be _really_ helpful to see what data is on the line and what might be missing. And also measure the pulse width...in case there's a clock mismatch somehow.

2. If you lower the clock speed, does it work?

3. Please let me know if Dave's code works for you.

4. If the above fails, I can order one of these and have it here next week. Then we can run your code on both Netduino and Netduino Plus 2 and figure out what's different. We definitely want to enable existing code to be re-used on the new boards.

Thank you for all your help getting to the bottom of this case,

Chris


1. Sorry I don't have logic analyzer.

2. I have tried at both the 100kHz and 400kHz; no success with either.

3. I had a look at the code Dave suggested and it is missing the some source from the example and the download link in the code doesn't point to the complete code. In the mean time i will try and look for a software i2c solution, not ideal though.

4. Any help to get a solution would be much appreciated.

Note: I have also tried with another sensor the Sparkfun BMP085 (https://www.sparkfun.com/products/9694); also has the 4.7k pull-ups; still doesn't respond.

#22 egeorgiou

egeorgiou

    Member

  • Members
  • PipPip
  • 28 posts
  • LocationLondon - United Kingdom

Posted 30 November 2012 - 10:05 PM

egeorgiou,

From the picture it looks like you have both the power and the ground plugged into the same row of the bread board, this will short out the power supply, please check your wiring?

Chuck


Hi Chuck,

the image isn't very clear, the lines are not connected together. That wouldn't be clever and I would have picked that up. The same board is moved to the N+1 and it works fine with the originally reference i2c code.

#23 carb

carb

    Advanced Member

  • Members
  • PipPipPip
  • 352 posts
  • LocationCrystal River, Florida

Posted 30 November 2012 - 10:07 PM

Hi Chuck,

the image isn't very clear, the lines are not connected together. That wouldn't be clever and I would have picked that up. The same board is moved to the N+1 and it works fine with the originally reference i2c code.

After the post I looked at the picture on a larger screen instead of a tablet and could see it was connected properly. Just didn't want you to smoke the board. :o

Chuck

#24 egeorgiou

egeorgiou

    Member

  • Members
  • PipPip
  • 28 posts
  • LocationLondon - United Kingdom

Posted 30 November 2012 - 10:08 PM

egeorgiou, your wiring looks fine. While I don't have that specific sensor, I have two of the individual sensors on that board, the Magnetometer and the Accelerometer. I will try to wire them up and see if I can get them working on my ND+2. Meanwhile can you share the code you are using? Perhaps it's a code issue. Today I tried the update with the DS1307 real time clock and that worked fine, but was not working fine with 4.2.1.0.


Hi Dave,

thanks!

Here is the code (I'm really sure it isn't the code because it work on the NP+1 and I'm not doing anything fancy and I'm 100% sure I'm reading from the correct register on the device and the address of the device is correct)

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;

namespace NetduinoPlusApplication_I2C_Example
{
    public class Program
    {
        public static void Main()
        {
            Byte[] _data = new byte[1] { 0 };

            I2CDevice adxl345 = new I2CDevice(new I2CDevice.Configuration(0x53, 100));
            I2CDevice.I2CWriteTransaction write = I2CDevice.CreateWriteTransaction(new Byte[] { 0x00 });
            I2CDevice.I2CReadTransaction read = I2CDevice.CreateReadTransaction(_data);
            I2CDevice.I2CTransaction[] actions = new I2CDevice.I2CTransaction[] { write, read };
            adxl345.Execute(actions, 1000);
            Debug.Print(_data[0].ToString());
        }

    }
}


#25 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 30 November 2012 - 10:11 PM

I just hacked out some code from one of my projects and hooked up the ADXL345. It does NOT work with the ND+2 so far. It is throwing an I2C error. I have to do a little more digging to try and get the exact error message, but so far it does NOT work.

#26 egeorgiou

egeorgiou

    Member

  • Members
  • PipPip
  • 28 posts
  • LocationLondon - United Kingdom

Posted 30 November 2012 - 10:15 PM

I just hacked out some code from one of my projects and hooked up the ADXL345. It does NOT work with the ND+2 so far. It is throwing an I2C error. I have to do a little more digging to try and get the exact error message, but so far it does NOT work.


Thanks for trying it out.

Is your ADXL345 set to high or low for the address?

#27 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 30 November 2012 - 10:20 PM

This is where the code is stopping in the stack. SecretLabs.NETMF.Hardware.Netduino.dll!SecretLabs.NETMF.Hardware.Netduino.NetduinoHardwareProvider.GetI2CPins(out Microsoft.SPOT.Hardware.Cpu.Pin scl = 0X00000000, out Microsoft.SPOT.Hardware.Cpu.Pin sda = 0x00000000) Line 51 Still trying to get an actual error message.

#28 carb

carb

    Advanced Member

  • Members
  • PipPipPip
  • 352 posts
  • LocationCrystal River, Florida

Posted 30 November 2012 - 10:23 PM

Hi Dave,

thanks!

Here is the code (I'm really sure it isn't the code because it work on the NP+1 and I'm not doing anything fancy and I'm 100% sure I'm reading from the correct register on the device and the address of the device is correct)

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;

namespace NetduinoPlusApplication_I2C_Example
{
    public class Program
    {
        public static void Main()
        {
            Byte[] _data = new byte[1] { 0 };

            I2CDevice adxl345 = new I2CDevice(new I2CDevice.Configuration(0x53, 100));
            I2CDevice.I2CWriteTransaction write = I2CDevice.CreateWriteTransaction(new Byte[] { 0x00 });
            I2CDevice.I2CReadTransaction read = I2CDevice.CreateReadTransaction(_data);
            I2CDevice.I2CTransaction[] actions = new I2CDevice.I2CTransaction[] { write, read };
            adxl345.Execute(actions, 1000);
            Debug.Print(_data[0].ToString());
        }

    }
}


Egeorgiou,

SecretLabs.NETMF.Hardware.NetduinoPlus needs to be replaced with just SecretLabs.NETMF.Hardware.Netduino. This is a change with the new firmware.

A few quick notes (known issues, temporary workarounds, etc.):

In the meantime, if you are upgrading your Netduino Plus 1 projects to Netduino Plus 2:

  • Remove the SecretLabs.NETMF.Hardware.NetduinoPlus.dll reference from your project.
  • Add the SecretLabs.NETMF.Hardware.Netduino.dll reference to your project
  • Change the deployment target in Project Properties > .NET Micro Framework.

Firmware Update Look at second post.

I tried your code on my NP2, at the first deploy it didn't work but I had no done this step "Change the deployment target in Project Properties > .NET Micro Framework." chnge to .NET Micro Framework 3.0 then back to 4.2 and the program deployed to the NP2. The output is shown in the picture
Chuck

Attached Files



#29 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 30 November 2012 - 10:26 PM

Egeorgiou, Yes Carb is Correct. You need to replace the DLL reference. It will however not fix it because I am using the correct DLL and still getting the error. But you should still replace it.

#30 egeorgiou

egeorgiou

    Member

  • Members
  • PipPip
  • 28 posts
  • LocationLondon - United Kingdom

Posted 30 November 2012 - 10:28 PM

Egeorgiou,

SecretLabs.NETMF.Hardware.NetduinoPlus needs to be replaced with just SecretLabs.NETMF.Hardware.Netduino. This is a change with the new firmware.

Firmware Update Look at second post.

Chuck


Well spotted!

My mistake I copied the wrong source from the example I used on the N+1; too many copies of VS open

Here is the code for the N+2
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace NetduinoApplication_I2C_Example
{
    public class Program
    {
        public static void Main()
        {
            Byte[] _data = new byte[1] { 0 };

            I2CDevice adxl345 = new I2CDevice(new I2CDevice.Configuration(0x53, 100));
            I2CDevice.I2CWriteTransaction write = I2CDevice.CreateWriteTransaction(new Byte[] { 0x00 });
            I2CDevice.I2CReadTransaction read = I2CDevice.CreateReadTransaction(_data);
            I2CDevice.I2CTransaction[] actions = new I2CDevice.I2CTransaction[] { write, read };
            adxl345.Execute(actions, 1000);
            Debug.Print(_data[0].ToString());

        }

    }
}


#31 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 30 November 2012 - 10:51 PM

Well spotted!

My mistake I copied the wrong source from the example I used on the N+1; too many copies of VS open

Here is the code for the N+2

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace NetduinoApplication_I2C_Example
{
    public class Program
    {
        public static void Main()
        {
            Byte[] _data = new byte[1] { 0 };

            I2CDevice adxl345 = new I2CDevice(new I2CDevice.Configuration(0x53, 100));
            I2CDevice.I2CWriteTransaction write = I2CDevice.CreateWriteTransaction(new Byte[] { 0x00 });
            I2CDevice.I2CReadTransaction read = I2CDevice.CreateReadTransaction(_data);
            I2CDevice.I2CTransaction[] actions = new I2CDevice.I2CTransaction[] { write, read };
            adxl345.Execute(actions, 1000);
            Debug.Print(_data[0].ToString());

        }

    }
}


This code should return the DeviceID correct? You are looking for a response of 0xE5 but you are getting 0?

#32 egeorgiou

egeorgiou

    Member

  • Members
  • PipPip
  • 28 posts
  • LocationLondon - United Kingdom

Posted 30 November 2012 - 10:53 PM

This code should return the DeviceID correct? You are looking for a response of 0xE5 but you are getting 0?


Yes, simply send 0x00 to the address 0x53; which should return 0xE5 or the integer 229.

#33 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 01 December 2012 - 02:23 AM

Hi Dave,

egeorgiou, your wiring looks fine. While I don't have that specific sensor, I have two of the individual sensors on that board, the Magnetometer and the Accelerometer. I will try to wire them up and see if I can get them working on my ND+2. Meanwhile can you share the code you are using? Perhaps it's a code issue. Today I tried the update with the DS1307 real time clock and that worked fine, but was not working fine with 4.2.1.0.

Just to confirm: is your DS1307 working via I2C now?

The I2C drivers in the NETMF STM32 core are the least widely-used drivers in the STM32 core. It's quite possible that we need to tweak them a bit to handle all I2C devices. We're standing by to do just that.

Chris

#34 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 01 December 2012 - 02:24 AM

For anyone having troubles with I2C (with the latest firmware): If there are specific I2C devices or scenarios which work on Netduino/Netduino Plus but don't work on Netduino Plus 2... If we can get the PNs for them and sample code to repro, we can address them each quickly. Please let me know what devices are/are not working, and let's drill into them and see if we can get this all wrapped up in a few days. We know that I2C is an important feature and want to make sure it's working well for everyone. There's actually some enhanced I2C capability we'd like to expose (repeated start bits, etc.) but we need to make sure the baseline I2C is working well across applications first. Chris P.S. egeorgiou, Dave, others: thanks for helping us diagnose and make these updates to NETMF.

#35 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 01 December 2012 - 03:25 AM

Hi Dave,


Just to confirm: is your DS1307 working via I2C now?

The I2C drivers in the NETMF STM32 core are the least widely-used drivers in the STM32 core. It's quite possible that we need to tweak them a bit to handle all I2C devices. We're standing by to do just that.

Chris


I don't believe it's working correctly. While it isn't crashing while trying to create an I2C device like it was in 4.2.1.0 it doesn't seem to be addressing the Chip. It never returns a valid ID using 4.2.1.1.

#36 DaveRVW

DaveRVW

    Advanced Member

  • Members
  • PipPipPip
  • 37 posts

Posted 01 December 2012 - 07:39 AM

Dave VanderWekke & egeorgiou

Please replace the Execute line in your code with the following to see how many total data bytes (reads and writes, not counting device addresses) have been sent in your transactions. This can help diagnose if the device is responding at all. The result should be the total number of bytes sent and received. Subtract the bytes sent (one in your case) and that's the total number of bytes received. If you haven't received any bytes, then probably don't print the read buffer contents.

int total = adxl345.Execute(actions, 1000);
Debug.Print(total + " bytes transferred successfully over I2C");

I have had success with DS1307 and 24FC1025 over both hardware and software I2C protocols with the Netduino Plus 2. Wishing you success soon too.

One more thing... it looks (according to SparkFun) like the 9 degrees of freedom stick can accept a variety of input voltages 3.3V-16V, while the ADXL345 breakout boards can only go up to 3.6V. I would only run a simple ADXL345 breakout at 3.3V, but as for that bigger board with more chips you may want to try an external power source or at least the 5V input instead. Or at least verify the current requirements. Just some thoughts to try to cover all the bases. And be careful with applying the right voltages.

#37 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 01 December 2012 - 12:19 PM

Dave VanderWekke & egeorgiou

Please replace the Execute line in your code with the following to see how many total data bytes (reads and writes, not counting device addresses) have been sent in your transactions. This can help diagnose if the device is responding at all. The result should be the total number of bytes sent and received. Subtract the bytes sent (one in your case) and that's the total number of bytes received. If you haven't received any bytes, then probably don't print the read buffer contents.

int total = adxl345.Execute(actions, 1000);
Debug.Print(total + " bytes transferred successfully over I2C");

I have had success with DS1307 and 24FC1025 over both hardware and software I2C protocols with the Netduino Plus 2. Wishing you success soon too.

One more thing... it looks (according to SparkFun) like the 9 degrees of freedom stick can accept a variety of input voltages 3.3V-16V, while the ADXL345 breakout boards can only go up to 3.6V. I would only run a simple ADXL345 breakout at 3.3V, but as for that bigger board with more chips you may want to try an external power source or at least the 5V input instead. Or at least verify the current requirements. Just some thoughts to try to cover all the bases. And be careful with applying the right voltages.


Thanks for the tip. I've already begin doing much the same type of code for all of the I2C devices I have here. I have several types of I2C devices that I can test. I've been working with Chris via Private Message to diagnose the issue.

#38 egeorgiou

egeorgiou

    Member

  • Members
  • PipPip
  • 28 posts
  • LocationLondon - United Kingdom

Posted 01 December 2012 - 09:19 PM

Dave VanderWekke & egeorgiou

Please replace the Execute line in your code with the following to see how many total data bytes (reads and writes, not counting device addresses) have been sent in your transactions. This can help diagnose if the device is responding at all. The result should be the total number of bytes sent and received. Subtract the bytes sent (one in your case) and that's the total number of bytes received. If you haven't received any bytes, then probably don't print the read buffer contents.

int total = adxl345.Execute(actions, 1000);
Debug.Print(total + " bytes transferred successfully over I2C");

I have had success with DS1307 and 24FC1025 over both hardware and software I2C protocols with the Netduino Plus 2. Wishing you success soon too.

One more thing... it looks (according to SparkFun) like the 9 degrees of freedom stick can accept a variety of input voltages 3.3V-16V, while the ADXL345 breakout boards can only go up to 3.6V. I would only run a simple ADXL345 breakout at 3.3V, but as for that bigger board with more chips you may want to try an external power source or at least the 5V input instead. Or at least verify the current requirements. Just some thoughts to try to cover all the bases. And be careful with applying the right voltages.


Hi Dave,

Thanks for your help. Still no luck, it returns 0.

I also tried at 5v but no luck. Even though on the N+1 it does work at 3.3v. Thanks, it was a good idea.

hoping for a solution soon. I have a horrible feeling it might be a hardware issue.

#39 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 02 December 2012 - 05:48 AM

Hi egeorgiou,

hoping for a solution soon. I have a horrible feeling it might be a hardware issue.

A bit of assurance for you: your hardware is fine. If there turns out to be some sort of defect on your specific board, we'll be happy to exchange it or offer an extended refund period for you. No worries; let's just get you up and running.

I2C is working well for some users, and for some other users we're seeing issues. Thank you (and Dave and others) for the code samples, repros, etc. We're digging in to these on a device-by-device basis and will continue solving the issues (and updating the firmware where needed) until I2C is performing as expected.

Once that's done, we'll get the software I2C features up and running on A4/A5 -- so that we work out of the box with both the new Arduino R2/R3 pinouts and the traditional R1 pinout. We designed the hardware to enable us to get the best of both worlds.

Chris




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.