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 1 and I2C

I2C Netduino plus 1

  • Please log in to reply
No replies to this topic

#1 w3n

w3n

    New Member

  • Members
  • Pip
  • 4 posts

Posted 29 December 2014 - 02:31 AM

Hi guys I need some help with I2C and Netduino plus 1.

 

Actually I'm using the A4-A5 Pins to try to communicate with an Adafruit servo shield but just noticied something that's getting me totally confused -I have to say I'm totally new on this but.. seems no sense-

 

Actually the Shield should be at the address 0x40 as documentation says.

 

Running the following test code I got confusing outputs:

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

namespace NetduinoPlusApplication2
{
    public class Program
    {
     
        static I2CDevice.Configuration _i2cdevice;
        public static void Main()
        {

                try
                {
                    Debug.Print("Trying addr: " + 0x38+ "------------------------------------");
                    _i2cdevice = new I2CDevice.Configuration(0x38, 400);
                    I2CDevice MyI2C = new I2CDevice(_i2cdevice);


                    I2CDevice.I2CTransaction[] xActions = new I2CDevice.I2CTransaction[2];

                    byte[] RegisterNum = new byte[1] { 2 };
                    xActions[0] = I2CDevice.CreateWriteTransaction(RegisterNum);

                    byte[] RegisterValue = new byte[1];
                    xActions[1] = I2CDevice.CreateReadTransaction(RegisterValue);

                    
                    if (MyI2C.Execute(xActions, 1000) == 0)
                    {
                        Debug.Print("Failed to perform I2C transaction");
                    }
                    else
                    {
                        Debug.Print("Register value: " + RegisterValue[0].ToString());
                    }
                }
                catch
                {
                    Debug.Print("EXCEPTION  "  );
                }

       
        }
    }
}

Notice I'm trying to setup it wrong, I2CDevice.Configuration(0x38, 400); ..but the output:

 

Trying addr: 56------------------------------------
Register value: 0
The thread '<No Name>' (0x1) has exited with code 0 (0x0).
Done.

 

Ok, Trying the 0x40 (64)

 

Trying addr: 64------------------------------------
Register value: 0
The thread '<No Name>' (0x1) has exited with code 0 (0x0).
Done.

 

and here comes the fun...I unplug the a4 and a5 and ..

 

First time I try: -It should say it failed as it does, so I guess this is right -

 

Trying addr: 64------------------------------------
Failed to perform I2C transaction
The thread '<No Name>' (0x1) has exited with code 0 (0x0).
Done.

 

Ok ..now let's try again -nothing is plugged-

 

The thread '<No Name>' (0x2) has exited with code 0 (0x0).
Trying addr: 64------------------------------------
Register value: 0
The thread '<No Name>' (0x1) has exited with code 0 (0x0).
Done.

How's this possible? first it reads something for an non present address, second time it reads from the 0x40, when it's unplugged it says it failed as expected the first time, but the second time says it was fine... I'm totally confused

 

Any idea on this? Thank you very much in advance

 







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.