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

I2CDevice extension


  • Please log in to reply
22 replies to this topic

#21 Patrick van Es

Patrick van Es

    Member

  • Members
  • PipPip
  • 14 posts

Posted 02 December 2010 - 06:32 PM

ok, i finally found the time to do some testing with the following code:

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

namespace NetduinoAppTest
{
    public class Program
    {
        static I2CDevice device = null;

        public static void Main()
        {
            // write your code here

            device = new I2CDevice( new I2CDevice.Configuration(0x42,400));
            device.Execute(new I2CDevice.I2CTransaction[]  {I2CDevice.CreateWriteTransaction(new byte[] { 0x73,0x42, 0x01,0x01,0x70  })}, 20); 
        }
    }
}

The byvac display doesn't even respond. I'm sure I must be doing something wrong but i can't find it..

#22 jbw

jbw

    Member

  • Members
  • PipPip
  • 10 posts

Posted 07 December 2010 - 03:21 AM

I'm trying to connect a BMA180 Accelerometer using the I2C connection. I have SDA and SCL to analog pins 4 and 5 respectively. VDD is connected to D1. VIO is connected to D0, which is turned on shortly after VDD is powered (as directed by datasheet). D0 is also connected to CSB, to allow I2C communication (as directed by BMA180 datasheet). I'm using 9 kOhm pullup resistors which are also wired to D0.

At this point I'm just trying to read anything from the device but have had no luck (readBuffer stays at 0). Here's my code, which attempts to access the LSB Z register, which should return something nonzero when the sensor is still (due to the acceleration from gravity).

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
using CW.NETMF.Hardware;
namespace BMA180
{
    public class BMA180
    {
        public static void Main()
        {
            ushort addr = 0x41;
            int clock_freq = 50;
            OutputPort VIO = new OutputPort(Pins.GPIO_PIN_D0, false);
            OutputPort VDD = new OutputPort(Pins.GPIO_PIN_D1, false);
            VDD.Write(true);//Power Sensor
            Thread.Sleep(50);//Wait a bit
            VIO.Write(true);//Power VIO
            byte[] writeBuffer = new byte[1] { 0x06 };//Z-MSB Register
            byte[] readBuffer = new byte[1];
            I2CDevice accelerometer = new I2CDevice(new I2CDevice.Configuration(addr, clock_freq));
       

            Thread.Sleep(20);
            
            int test = accelerometer.WriteRead(writeBuffer, readBuffer, 1000, I2COptions.RepeatStart);

           
        }

    }
}


#23 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 28 December 2010 - 01:48 AM

Quick update...based on CW2's excellent work, we've added I2C "repeated start bit" extensions to the Netduino v4.1.1 alpha 4 firmware. We're wrapping up testing now (and fixing a few non-related .NET MF bugs), and will post it by the weekend. 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.