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

Intro to Netduino I2C?

I2C

  • Please log in to reply
9 replies to this topic

#1 Verdris

Verdris

    Advanced Member

  • Members
  • PipPipPip
  • 128 posts
  • LocationReno, NV

Posted 17 January 2013 - 09:57 AM

Hi all,

 

I have a digital potentiometer I'm trying to get working with the Netduino. It's I2C, obviously. I've gotten this part working quite well with the Arduino and ChipKit boards, but I'm utterly confused by how I2C works in NETMF. I've looked all over and have found numerous examples, but nothing that really tells me exactly what each command does and how to do basic things such as read and write. Are there any such resources that have just escaped me?

 

If it would help, I can post the Arduino/ChipKit library I wrote for this part. It's the AD5175.



#2 korbai

korbai

    Member

  • Members
  • PipPip
  • 17 posts

Posted 17 January 2013 - 10:36 AM

Hello,

 

This is a sample for a PCF8574 digital i/o expander.

Flashing all 8 bit ouputs.

    public class Program    {        public static void Main()        {            var device = new I2CDevice(new I2CDevice.Configuration(0x38, 100));            I2CDevice.I2CTransaction[] actionsWrite;            var buffer = new byte[1];            actionsWrite = new I2CDevice.I2CTransaction[]            {                I2CDevice.CreateWriteTransaction(buffer),            };            for (; ; )            {                buffer[0] = 255;                device.Execute(actionsWrite, 1000);                Thread.Sleep(1000);                buffer[0] = 0;                device.Execute(actionsWrite, 1000);                Thread.Sleep(1000);            }        }    }


#3 Verdris

Verdris

    Advanced Member

  • Members
  • PipPipPip
  • 128 posts
  • LocationReno, NV

Posted 17 January 2013 - 09:39 PM

Hello,

 

This is a sample for a PCF8574 digital i/o expander.

Flashing all 8 bit ouputs.

    public class Program    {        public static void Main()        {            var device = new I2CDevice(new I2CDevice.Configuration(0x38, 100));            I2CDevice.I2CTransaction[] actionsWrite;            var buffer = new byte[1];            actionsWrite = new I2CDevice.I2CTransaction[]            {                I2CDevice.CreateWriteTransaction(buffer),            };            for (; ; )            {                buffer[0] = 255;                device.Execute(actionsWrite, 1000);                Thread.Sleep(1000);                buffer[0] = 0;                device.Execute(actionsWrite, 1000);                Thread.Sleep(1000);            }        }    }

Thanks. Can you explain why I need to specify a timeout for the write transaction?



#4 korbai

korbai

    Member

  • Members
  • PipPip
  • 17 posts

Posted 18 January 2013 - 08:39 AM

Thanks. Can you explain why I need to specify a timeout for the write transaction?

Because end of every byte there is an acknowledge bit from slave device.

If no ACK you know something  wrong (wire problem, resistor problem, wrong slave address).



#5 Verdris

Verdris

    Advanced Member

  • Members
  • PipPipPip
  • 128 posts
  • LocationReno, NV

Posted 19 January 2013 - 12:14 AM

Because end of every byte there is an acknowledge bit from slave device.

If no ACK you know something  wrong (wire problem, resistor problem, wrong slave address).

I get that, but is there something special about using 1000 as the value for the timeout? Is that 1 second that my microcontroller is just sitting there waiting, or is that acting like a maximum amount of time it will wait before it decides to throw up an error?



#6 korbai

korbai

    Member

  • Members
  • PipPip
  • 17 posts

Posted 19 January 2013 - 08:49 AM

I get that, but is there something special about using 1000 as the value for the timeout? Is that 1 second that my microcontroller is just sitting there waiting, or is that acting like a maximum amount of time it will wait before it decides to throw up an error?

It return immediately if got answer. Waiting 1 sec when no answer.



#7 kash

kash

    New Member

  • Members
  • Pip
  • 6 posts

Posted 27 March 2013 - 07:41 PM

Hello,

I did run this code on Netduino plus with 4.1 vesion with no device attached to I2C port. I used 4.7k pull ups. When I look at the pins (A4, A5)  with my scope, I just see 5 volts DC(3.3volts) and  no signal. Do I need to have a device attached?.

I did this to make sure, it is not my device that is causing no signal.

Thank you,

Kash



#8 jcdonelson

jcdonelson

    New Member

  • Members
  • Pip
  • 2 posts

Posted 13 August 2013 - 02:29 AM

Just one problem (at least) with the PCF8574 code - the device address is 0x20 not 0x38.

(http://www.ti.com/li...ink/pcf8574.pdf page 4)

If you write and no device is there you should see the address sent out.



#9 korbai

korbai

    Member

  • Members
  • PipPip
  • 17 posts

Posted 13 December 2013 - 06:37 AM

Just one problem (at least) with the [color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]PCF8574 code - the device address is 0x20 not 0x38.[/color]

[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]([/color]http://www.ti.com/li...ink/pcf8574.pdf page 4)

[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]If you write and no device is there you should see the address sent out.[/color]

Yes, you are right.

But pay attention there is a device with 'A' postfix: PCF8574A, it has 0x38 base address:

http://www.ti.com/li...nk/pcf8574a.pdf



#10 hunter0720

hunter0720

    New Member

  • Members
  • Pip
  • 2 posts

Posted 06 September 2014 - 02:19 AM

Hi Guys!, im pretty new into the forum, i have several doubts about if netduino 1 (with firmware 4.1) can use i2c, and if so, where can i find classes or libraries to do so.

 

Thanks 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.