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

I2C Bus not working


  • Please log in to reply
11 replies to this topic

#1 k0fei

k0fei

    Member

  • Members
  • PipPip
  • 10 posts

Posted 31 December 2013 - 07:02 PM

I can't get the SDA and SCL pins on a Netduino Plus 2 to respond using the I2CDevice class.  The logic analyzer sees no clock or data, the lines just stay high.  I have 10k pull-up resistors.  I can control the pins as output and the SoftwareI2C code drives them at a about 1.5 khz.  I have tried it on two brand new boards, the same result.  I must be doing something wrong.  This is the 4.2.2.2 firmware that comes on new boards.

 

Thanks - Frank

 



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 01 January 2014 - 03:06 AM

Hi Frank, What does your code look like, using I2CDevice? SDA/SCL pins should work great in hardware I2C mode. Chris

#3 k0fei

k0fei

    Member

  • Members
  • PipPip
  • 10 posts

Posted 31 December 2013 - 06:25 PM

I am trying to read a TMP100 temperature sensor.  It works when I use the I2C Software emulation code SoftwareI2CBus so I know the hardware is good.  When I try using I2CDevice the SCL and SDA pins just stay high.  I have a Saleae Logic 16 on the pins.  I see data using the software emulation but not using the I2CDevice.

 

Here is the code:

 

[color=#2d2cfa;]using[/color] System;

[color=#2d2cfa;]using[/color] System.Net;

[color=#2d2cfa;]using[/color] System.Net.Sockets;

[color=#2d2cfa;]using[/color] System.Threading;

[color=#2d2cfa;]using[/color] Microsoft.SPOT;

[color=#2d2cfa;]using[/color] Microsoft.SPOT.Hardware;

[color=#2d2cfa;]using[/color] SecretLabs.NETMF.Hardware;

[color=#2d2cfa;]using[/color] SecretLabs.NETMF.Hardware.Netduino;

 

namespace[color=#000000;] I2CTest[/color]

{

[color=#000000;]    [/color]public[color=#000000;] [/color]class[color=#000000;] [/color][color=#34a2bb;]Program[/color]

    {

        [color=#2d2cfa;]public[/color] [color=#2d2cfa;]static[/color] [color=#2d2cfa;]void[/color] Main()

        {

[color=#000000;]            [/color]I2CDevice[color=#000000;].[/color]Configuration[color=#000000;] config = [/color][color=#2d2cfa;]new[/color][color=#000000;] [/color]I2CDevice[color=#000000;].[/color]Configuration[color=#000000;](0x48, 100);[/color]

            [color=#34a2bb;]I2CDevice[/color] dev = [color=#2d2cfa;]new[/color] [color=#34a2bb;]I2CDevice[/color](config);

 

[color=#000000;]            [/color]// Make the transactions

 

            [color=#34a2bb;]Byte[/color][] tempData = [color=#2d2cfa;]new[/color] [color=#34a2bb;]Byte[/color][2];

 

            [color=#2d2cfa;]var[/color] transaction = [color=#2d2cfa;]new[/color] [color=#34a2bb;]I2CDevice[/color].[color=#34a2bb;]I2CTransaction[/color][] {

                [color=#34a2bb;]I2CDevice[/color].CreateWriteTransaction([color=#2d2cfa;]new[/color] [color=#34a2bb;]Byte[/color][] {0x00}),

                [color=#34a2bb;]I2CDevice[/color].CreateReadTransaction(tempData)

            };

 

            [color=#34a2bb;]Int32[/color] bytesTransfered = dev.Execute(transaction, 300);

            [color=#2d2cfa;]if[/color] ( bytesTransfered == 0)

            {

[color=#000000;]                [/color][color=#2d2cfa;]throw[/color][color=#000000;] [/color][color=#2d2cfa;]new[/color][color=#000000;] [/color][color=#34a2bb;]Exception[/color][color=#000000;]([/color]"I2C transaction failed"[color=#000000;]);[/color]

            }

 

            [color=#34a2bb;]UInt16[/color] utmp = tempData[0];

            utmp <<= 8;

            utmp |= tempData[1];

 

            [color=#34a2bb;]Int16[/color] tmp = ([color=#34a2bb;]Int16[/color])utmp;

            [color=#34a2bb;]Double[/color] temp = ([color=#34a2bb;]Double[/color])tmp;

            temp /= ([color=#34a2bb;]Double[/color])256;

 

 

 

        [color=#34a2bb;]Debug[/color].Print(temp.ToString() + [color=#b51f20;]" Degrees C"[/color]);

    }

    }

}



#4 jrlyman3

jrlyman3

    Advanced Member

  • Members
  • PipPipPip
  • 67 posts
  • LocationNorth St Paul. MN

Posted 02 January 2014 - 03:10 AM

Are you sure you're hooked up to the right pins? So which pins are you connecting to?



#5 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 02 January 2014 - 08:54 AM

To echo jrlyman3: Is your logic analyzer attached to the dedicated I2C pins ("SD" and "SC" near pin D13) or to pins A4/A5? How are the pull-ups attached? If you want to post your SoftwareI2C code, that might help a bit too. Chris

#6 k0fei

k0fei

    Member

  • Members
  • PipPip
  • 10 posts

Posted 02 January 2014 - 11:43 PM

I am hooked up to the right pins - SCL and SDA.  I actually have 3 devices on that bus - the TMP100, a DS1307 and a MCP2301 port expander.  I am using 10K pull-ups.  I'll write a test program using the SoftwareI2C code.  My development code is using the SofwareI2CBus and some hacks so I can multi-thread for the devices (as well as the bug fix I posted on another thread).

 

The Logic 16 is indeed connected to the SCL and SDA pins.  I see the data under the SoftwareI2C (that is how I found that SoftwareI2CBus was sending an ACK not a NAK on the last byte to be read from a slave), but no data at all - even an address - under hardware I2C.  I tried the same test program on a brand new out of the box Netduino Plus 2 fresh from Mouser - still no luck.  I was hoping someone could tell me what I messed up in my test program.



#7 jrlyman3

jrlyman3

    Advanced Member

  • Members
  • PipPipPip
  • 67 posts
  • LocationNorth St Paul. MN

Posted 07 January 2014 - 04:42 AM

I compared your code to mine and I don't see much difference, I used a timeout of 1000 on the execute function, but that should not be an issue.  I know that I had a issue when I went back to a NetduinoPlus1 which uses A4/A5, but I don't see how you would mistake the SCL/SDA pins on the NetduinoPlus2 board.  I also ran into a problem with bus contention (I have another microcontroller on the bus) but that doesn't apply to this.  So, other than to say it seems to work for me, I guess I can't be much help.  I did notice one other thing, you're using the Netduino library instead of the NetduinoPlus library you might want to try changing that.

 

Sorry I can't be more help.

 

John



#8 inomine

inomine

    New Member

  • Members
  • Pip
  • 2 posts

Posted 09 January 2014 - 11:57 AM

I initially ran into the same issue, TMP100 seemingly not working with hardware I2C on a netduino plus 2, using k0fei's code. The same sensor hardware worked fine on an Arduino.

 

The fix for the netduino was to add 4k7 pullup resistors on SDA and SCL. So it looks like while for the Arduino and for SoftwareSerial we can get away without them, the dedicated I2C lines need to be used more in line with real I2C bus specs.



#9 yogotie

yogotie

    Member

  • Members
  • PipPip
  • 16 posts

Posted 12 January 2014 - 04:21 PM

Hardware mode for the Plus 2 has an issue where it is possible for the I2C module in the micro to become locked up.

 

You can look through my debugging post here, http://forums.netdui...sue/#entry49515, and see if this looks like what you maybe seeing.

 

If this is your issue and you don't want to use my firmware the try using a lower value pullup resistor, such as 1k, to reduce the probability of the lockup condition.



#10 k0fei

k0fei

    Member

  • Members
  • PipPip
  • 10 posts

Posted 17 January 2014 - 10:14 PM

I will try the custom.ufd in the thread above, but it sounds like it is going to fix it.  Hopefully the Netduino folks will include your fix in the next release - or at least add a bug to their list about I2C problems.  Thanks for pointing me to what looks like a solution.



#11 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 18 January 2014 - 01:48 AM

Hmm, interesting. We weren't aware of this. Did the custom firmware work around the issue for you? We'll dig into I2C bus state with the 4.3 firmware release.

#12 PScarlett

PScarlett

    New Member

  • Members
  • Pip
  • 1 posts

Posted 02 June 2014 - 12:49 AM

Hi there ... new to this world and just spent some time leaning a lesson..

 

I have a just built a Adafruit DS1307 RTC ... tested it on Sparkfun Red Board -- Arduino Uno equivalent -- all worked fine. 

 

So I moved to a Netduino Plus .. no luck as I believe it is a problem with the upgrade to NetMF 4.2   So I move to my new NetDunio Plus 2. (NP2)  Still no luck.   ugh!

 

After several false starts and several different code samples, I finally check the forum and discovered the above posts.  Based on this I got it to work.

 

The issue is using the analog A4/A5 vs SDA/SCL pins.   On the Sparkfun Red board, you can use either the A4/A5 or SDA/SCL pin and either set works.   On the Netduino Plus you must use A4/A5 as no explicit SDA/SCL exist.

 

On the NP2, it appears you must use the SDA/SCL pins.  I had moved from the Red board, to the Netduino Plus and move the pins to the same pins as I had used on the Red Board, then discovered issue related to 4.2 update, so moved to NP2 using the same pins as before - A4/A5/Gnd/V5 - with no luck.

 

Bottom line - all is working using SDA/SCL/Gnd/V5 on the NP2.

 

Hope this helps others who are just starting out ..   Any comments or insights would be appreciated. 

 

Paul.






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.