Support understanding I2C comms - 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

Support understanding I2C comms


Best Answer Rik P., 03 January 2014 - 03:20 PM

Hi Rik, With NETMF, you'll want to dispose of one I2CDevice object before creating another: each I2CDevice class reserves the I2C bus. Chris

 

Thanks, Chris. 

 

Rik

Go to the full post


  • Please log in to reply
4 replies to this topic

#1 Rik P.

Rik P.

    Member

  • Members
  • PipPip
  • 18 posts

Posted 31 December 2013 - 03:48 PM

Hello all

 

I've been lucky enough to get hold of a Sparkfun 9DOF sensor stick (https://www.sparkfun.../products/10736), which uses I2C for communication. Whilst I've spent a lot of time reading up on I2C (as this is not something I have any experience with), and I'm fairly confident now with the programming model, I'm not really sure how to get started reading the sensor values from the device via I2C.

 

The sensor board has three onboard sensors, one of which is an ADXL345.According to the manual, this is addressed on 0x53. 

 

Am I write in assuming I need to instantiate a new I2CDevice.Configuration object as follows?

var config = new I2CDevice.Configuration(0x53,400);

If that's correct, this allows me to target that device on the bus (I think). What I now need to do is 'poll' the bus on a periodic basis to retrieve the current sensor values. And this is the part I am struggling with...

 

The manual says the register for "X Axis Data 0" is at 0x32, and "X Axis Data 1" is at 0x33. I figured I need to create a Read transaction, but the APIs don't seem to have any parameters which target the registers I want to read from?

var rxBuffer = new byte[4];var readTransaction = new I2CDevice.I2CTransaction[]{   I2CDevice.CreateReadTransaction(rxBuffer)};adxlDevice.Execute(readTransaction, 1000);

With this in mind, I'm not entirely sure what I'm supposed to do in order to obtain values from the registers. My guess, is that I'm going about this completely the wrong way and would really appreciate a steer. 

 

Any help?

 

Many thanks.

 

 


---
Twitter: @rikp


#2 Stanislav Husár

Stanislav Husár

    Advanced Member

  • Members
  • PipPipPip
  • 99 posts

Posted 31 December 2013 - 06:05 PM

Hi,

 

 

Reading values from I2C sensor´s memory is simple.

At first, you need I2CConfiguration object. But this object is just a configuration.

So, you need I2CDevice object.

 

Then you create an array of type I2CTransaction with two elements.

As first element you use I2CWriteTransaction. You write address, from which you want to read, to the device.

Second element would be I2CReadTranscation. With this transaction, you read data from selected address.

 

Finally, you call I2CDevice.Execute().

 

Hope this helps.



#3 Rik P.

Rik P.

    Member

  • Members
  • PipPip
  • 18 posts

Posted 01 January 2014 - 10:21 AM

Hi Stanislav,

 

Thank you for your reply, this has helped a lot.

 

I do have one follow-up query, if you don't mind. I can read from any one device at a time using the code I've written, however I cannot initialise two devices on the I2C bus, and then read from them both in sequence. When I attempt to do this, I receive an InvalidOperationException. My guess is this has to do with timing.

 

Any ideas?

 

Thanks


---
Twitter: @rikp


#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 02 January 2014 - 08:38 AM

Hi Rik, With NETMF, you'll want to dispose of one I2CDevice object before creating another: each I2CDevice class reserves the I2C bus. Chris

#5 Rik P.

Rik P.

    Member

  • Members
  • PipPip
  • 18 posts

Posted 03 January 2014 - 03:20 PM   Best Answer

Hi Rik, With NETMF, you'll want to dispose of one I2CDevice object before creating another: each I2CDevice class reserves the I2C bus. Chris

 

Thanks, Chris. 

 

Rik


---
Twitter: @rikp





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.