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 Software Workaround for Plus 2


  • Please log in to reply
30 replies to this topic

#1 DaveRVW

DaveRVW

    Advanced Member

  • Members
  • PipPipPip
  • 37 posts

Posted 30 November 2012 - 07:46 AM

This SoftwareI2CBus class can be used to help workaround Netduino Plus 2 I2C problems.

I was able to successfully read from my I2C EEPROM. Another advantage is that you can choose to use different pins too.

(Note this leverages a software I2C driver written by our peers over at tinyclr and GHI. Note that a portion must be downloaded from the tinyclr site (link will show when you try to compile). The value I added was to replace the custom APIs with ones more compatible with the standard I2C APIs. Known issue: read/write timeouts are either fixed or otherwise ignored.)


Good luck guys! The Netduino Plus 2 is a great platform, and hopefully this can help one or two folks that hit the early defects in I2C.

Usage comparison between hardware and software I2C:

#define I2C_SOFTWARE
#if I2C_SOFTWARE
            SoftwareI2CBus i2cbus = new SoftwareI2CBus(Pins.GPIO_PIN_A5, Pins.GPIO_PIN_A4);
            SoftwareI2CBus.I2CDevice i2c = i2cbus.CreateI2CDevice(new I2CDevice.Configuration(0x50, 400));
#endif
#if I2C_HARDWARE
            I2CDevice i2c = new I2CDevice(new I2CDevice.Configuration(0x50, 400));
#endif

Attached Files



#2 DaveRVW

DaveRVW

    Advanced Member

  • Members
  • PipPipPip
  • 37 posts

Posted 30 November 2012 - 08:14 AM

Lol! I see Chris posted an I2C fix 25 minutes earlier than my workaround.

I am looking forward to trying out the fix, and will probably keep using the workaround to avoid jumpering SCL/SDA until the official Secret Labs mirroring I2C solution is available.

#3 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 30 November 2012 - 08:17 AM

Hi Dave,

Usage comparison between hardware and software I2C:

#define I2C_SOFTWARE
#if I2C_SOFTWARE
            SoftwareI2CBus i2cbus = new SoftwareI2CBus(Pins.GPIO_PIN_A5, Pins.GPIO_PIN_A4);
            SoftwareI2CBus.I2CDevice i2c = i2cbus.CreateI2CDevice(new I2CDevice.Configuration(0x50, 400));
#endif
#if I2C_HARDWARE
            I2CDevice i2c = new I2CDevice(new I2CDevice.Configuration(0x50, 400));
#endif

Very cool. Thanks for creating this software I2C solution.

This actually has a lot of uses beyond using A4/A5... If users need 10 I2C buses (for instance if they have 10 I2C devices with the same I2C address) they could use your code for that.

Chris

#4 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 02 December 2012 - 06:52 PM

This SoftwareI2CBus class can be used to help workaround Netduino Plus 2 I2C problems.

I was able to successfully read from my I2C EEPROM. Another advantage is that you can choose to use different pins too.

(Note this leverages a software I2C driver written by our peers over at tinyclr and GHI. Note that a portion must be downloaded from the tinyclr site (link will show when you try to compile). The value I added was to replace the custom APIs with ones more compatible with the standard I2C APIs. Known issue: read/write timeouts are either fixed or otherwise ignored.)


Good luck guys! The Netduino Plus 2 is a great platform, and hopefully this can help one or two folks that hit the early defects in I2C.

Usage comparison between hardware and software I2C:

#define I2C_SOFTWARE
#if I2C_SOFTWARE
            SoftwareI2CBus i2cbus = new SoftwareI2CBus(Pins.GPIO_PIN_A5, Pins.GPIO_PIN_A4);
            SoftwareI2CBus.I2CDevice i2c = i2cbus.CreateI2CDevice(new I2CDevice.Configuration(0x50, 400));
#endif
#if I2C_HARDWARE
            I2CDevice i2c = new I2CDevice(new I2CDevice.Configuration(0x50, 400));
#endif


I played around with this a bit. Very useful code. I was able to get a few things up and running just for testing purposes. A few of the sensors I have don't seem to work with the Software solution. I didn't spend much time on it because it would be a major rewrite to get some of my code working. It still proved useful to get the DS1307 running in order to continue prototyping a portion of my project.

Thank you for contributing this.

#5 DaveRVW

DaveRVW

    Advanced Member

  • Members
  • PipPipPip
  • 37 posts

Posted 02 December 2012 - 09:13 PM

I played around with this a bit. Very useful code. I was able to get a few things up and running just for testing purposes. A few of the sensors I have don't seem to work with the Software solution. I didn't spend much time on it because it would be a major rewrite to get some of my code working. It still proved useful to get the DS1307 running in order to continue prototyping a portion of my project.

Thank you for contributing this.


Good to hear the feedback. And I'm lucky to be leveraging someone else's underlying software I2C driver so I can blame them for anything that didn't work :-)

As for the DS1307, I was able to wire a bare DS1307 PDIP-8 package, 32.768kHz crystal, plus 3.3K pull-up resistors, ground VBAT as not used, leaving SQW/OUT unwired, then wired directly to the Plus 2 using the SC/SD pins, and successfully communicated to it using the hardware solution (using NP2 Update 1 of course). I set the time at the top of my program, and on a loop see the time advance.

Have you been able to get the DS1307 to work using the hardware solution? Or are you using the software solution so you can use different pins?

#6 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 02 December 2012 - 11:34 PM

Good to hear the feedback. And I'm lucky to be leveraging someone else's underlying software I2C driver so I can blame them for anything that didn't work :-)

As for the DS1307, I was able to wire a bare DS1307 PDIP-8 package, 32.768kHz crystal, plus 3.3K pull-up resistors, ground VBAT as not used, leaving SQW/OUT unwired, then wired directly to the Plus 2 using the SC/SD pins, and successfully communicated to it using the hardware solution (using NP2 Update 1 of course). I set the time at the top of my program, and on a loop see the time advance.

Have you been able to get the DS1307 to work using the hardware solution? Or are you using the software solution so you can use different pins?


So far I haven't been able to get anything I2C related working with then ND+2 using Hardware I2C.

Basically what I am seeing is the transferred bytes is showing 0 (zero). What I found interesting is when it creates the new I2CDevice (adxl345) the object type in the ND+ shows as {Microsoft.SPOT.Hardware.I2CDevice} but in the ND+2 it shows as {Microsoft.SPOT.Hardware.Battery.ChargerModel}. Also if I run a watch on "new I2CDevice.Configuration(0x53, 400)" you can see that the Address and Speed get reversed in the object although this is the correct parameter order. I get the same results with all I2C modules I have here (listed below the code).

I2CDevice i2c = new I2CDevice(new I2CDevice.Configuration(0x53, 400));
I2CDevice.I2CWriteTransaction write = I2CDevice.CreateWriteTransaction(new Byte[] { 0x00 });
I2CDevice.I2CReadTransaction read = I2CDevice.CreateReadTransaction(_data);
I2CDevice.I2CTransaction[] actions = new I2CDevice.I2CTransaction[] { write, read };
int total = i2c.Execute(actions, 1000);
Debug.Print(total + " bytes transferred successfully over I2C");
Debug.Print(_data[0].ToString());

1) BMP085 Barometric Pressure Sensor - http://www.sparkfun.com/products/9694

2) HMC5883L 3 Axis Compass - http://www.parallax....ame,ProductName

3) ADXL345 3 Axis Accelerometer - https://www.sparkfun.com/products/9156

4) DS1307 Real Time Clock - https://www.adafruit.com/products/264

5) LCD Backpack - https://www.adafruit.com/products/292

#7 DaveRVW

DaveRVW

    Advanced Member

  • Members
  • PipPipPip
  • 37 posts

Posted 03 December 2012 - 02:16 AM

Something subtle must be wrong for your DS1307 not to work on the NP2 while mine does. Try this attached project and compare the output to mine.

[Build]
------ Deploy started: Project: DS1307, Configuration: Debug Any CPU ------
========== Deploy: 1 succeeded, 0 failed, 0 skipped ==========

[Micro Framework Device Deployment]
Incrementally deploying assemblies to device
Deploying assemblies for a total size of 1112 bytes
Assemblies successfully deployed to device.

[Debug]
Create TS.

 Loading start at 806a240, end 8085f7c

Assembly: mscorlib (4.2.0.0)

Assembly: Microsoft.SPOT.Native (4.2.0.0)

Assembly: Microsoft.SPOT.Hardware (4.2.0.0)

Assembly: Microsoft.SPOT.Net (4.2.0.0)

Assembly: System (4.2.0.0)

Assembly: Microsoft.SPOT.Hardware.SerialPort (4.2.0.0)

Assembly: Microsoft.SPOT.IO (4.2.0.0)

Assembly: System.IO (4.2.0.0)

Assembly: Microsoft.SPOT.Hardware.PWM (4.2.0.1)

Assembly: Microsoft.SPOT.Hardware.Usb (4.2.0.0)

Assembly: SecretLabs.NETMF.Diagnostics (4.2.0.0)

Assembly: SecretLabs.NETMF.Hardware.Netduino (4.2.1.0)

Assembly: Microsoft.SPOT.Hardware.OneWire (4.2.0.0)

Assembly: Microsoft.SPOT.Time (4.2.0.0)

Loading Deployment Assemblies.

Attaching deployed file.

Assembly: DS1307 (1.0.0.0)

Resolving.

The debugging target runtime is loading the application assemblies and starting execution.
Ready.

I2C transacted 9 bytes
I2C transacted 9 bytes
55 59 23 06 30 11 12 00 
I2C transacted 9 bytes
56 59 23 06 30 11 12 00 
I2C transacted 9 bytes
57 59 23 06 30 11 12 00 
I2C transacted 9 bytes
58 59 23 06 30 11 12 00 
I2C transacted 9 bytes
59 59 23 06 30 11 12 00 
I2C transacted 9 bytes
00 00 00 07 01 12 12 00 
I2C transacted 9 bytes
01 00 00 07 01 12 12 00 

p.s. I'm seeing the Microsoft.SPOT.Hardware.Battery.ChargerModel in QuickWatch too for the I2CDevice. That's weird.

#8 DaveRVW

DaveRVW

    Advanced Member

  • Members
  • PipPipPip
  • 37 posts

Posted 03 December 2012 - 02:17 AM

(nothing to see here, move along to the next reply)

#9 DaveRVW

DaveRVW

    Advanced Member

  • Members
  • PipPipPip
  • 37 posts

Posted 03 December 2012 - 02:18 AM

Finally got the attachment

Attached Files



#10 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 03 December 2012 - 02:55 AM

Finally got the attachment


I'll Give it a shot tomorrow. As you can see from my Earlier Parts list, I'm using the DS1307 breakout from adafruit. I'll have to check the schematic to see what resistors they have but I think it was 2.2k, otherwise the chip and crystal are the same. I'll give your code a shot tomorrow and report back.

Thanks for taking the time to post it up.

#11 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 03 December 2012 - 09:32 AM

Hi Dave,

Basically what I am seeing is the transferred bytes is showing 0 (zero). What I found interesting is when it creates the new I2CDevice (adxl345) the object type in the ND+ shows as {Microsoft.SPOT.Hardware.I2CDevice} but in the ND+2 it shows as {Microsoft.SPOT.Hardware.Battery.ChargerModel}.

On Battery.ChargerModel...it looks like the debugger link is one method off. This is something we can fix...but it is most likely just cosmetic. We're rebuilding the source one piece at a time to see what's throwing it off.

Regarding I2C...we found one more bug. I2C was working consistently for us when we deployed an app...but when we powered on the board or configured the pins in our app, it no longer worked. This is fixed in the new 4.2.1.2 release (just posted).

At this point, if there are any remaining I2C glitches we'll start analyzing individual configurations. We're happy to do so...but hopefully I2C is working great for everyone (or almost everyone) now--on the SDA/SCL pins.

Chris

#12 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 03 December 2012 - 10:53 AM

Hi Dave,


On Battery.ChargerModel...it looks like the debugger link is one method off. This is something we can fix...but it is most likely just cosmetic. We're rebuilding the source one piece at a time to see what's throwing it off.

Regarding I2C...we found one more bug. I2C was working consistently for us when we deployed an app...but when we powered on the board or configured the pins in our app, it no longer worked. This is fixed in the new 4.2.1.2 release (just posted).

At this point, if there are any remaining I2C glitches we'll start analyzing individual configurations. We're happy to do so...but hopefully I2C is working great for everyone (or almost everyone) now--on the SDA/SCL pins.

Chris


Nice waking up to new releases :D. I'll flash it and give it a try. I'll post the results in a few hours.

#13 rgoode214

rgoode214

    Member

  • Members
  • PipPip
  • 18 posts
  • LocationSan Antonio, TX

Posted 18 December 2012 - 08:09 AM

ran across this thread because im running into the same troubles getting I2C to work properly. I flashed my N+2 with the 4.2.1.2 firmware and tried the test program provided a few posts above and im getting nothing back. I thought maybe it was a problem with the DS1307 (from sparkfun) so i tried it on the arduino i have and it works fine. I doubt that the device is having a hardware issue but unfortunately i dont have any other way to test it. Ryan

#14 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 18 December 2012 - 12:03 PM

ran across this thread because im running into the same troubles getting I2C to work properly. I flashed my N+2 with the 4.2.1.2 firmware and tried the test program provided a few posts above and im getting nothing back. I thought maybe it was a problem with the DS1307 (from sparkfun) so i tried it on the arduino i have and it works fine.

I doubt that the device is having a hardware issue but unfortunately i dont have any other way to test it.

Ryan


I can verify that DS1307 works with Version 4.2.1.2. So lets walk through your setup. How is it wired? Are you using the new SDA & SCL pins? Is the sensor wired to 5V or 3.3V? Can you post up a sample of your code?

#15 rgoode214

rgoode214

    Member

  • Members
  • PipPip
  • 18 posts
  • LocationSan Antonio, TX

Posted 18 December 2012 - 06:56 PM

Sure, thanks for the help. Its wired as 5V -> 5V, GND -> GND, SCL -> SC, SDA -> SD and the code i was using was the one from a few posts up. I plugged it back into the arduino and now im getting nothing back on that board as well. *shrug* Ive got a second one coming in the mail anyways so ill test that one when it gets here but ill take a look at the solder joints, maybe i messed one up and the connection isnt good. Ryan

#16 mtylerjr

mtylerjr

    Advanced Member

  • Members
  • PipPipPip
  • 106 posts
  • LocationChristchurch, New Zealand

Posted 18 December 2012 - 07:01 PM

I can verify that DS1307 works with Version 4.2.1.2. So lets walk through your setup. How is it wired? Are you using the new SDA & SCL pins? Is the sensor wired to 5V or 3.3V? Can you post up a sample of your code?


"new SDA & SCL pins" ???

Are we not using 4 and 5 anymore?

I think I need to write an AI data-mining agent to sift through the forums for these bits of info... when/where/why/how were the pins changed?

#17 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 18 December 2012 - 07:44 PM

"new SDA & SCL pins" ???

Are we not using 4 and 5 anymore?

I think I need to write an AI data-mining agent to sift through the forums for these bits of info... when/where/why/how were the pins changed?


The Netduino Plus 2 has an extended Header that has separate SDA and SCL pins. Right now the firmware only supports these pins. You would need to jump to the A4/A5 pins to use older shields with the Netduino Plus 2. Chris is working on some updates to allow the firmware to be configured to use either setup, but this is too come.

#18 mtylerjr

mtylerjr

    Advanced Member

  • Members
  • PipPipPip
  • 106 posts
  • LocationChristchurch, New Zealand

Posted 18 December 2012 - 08:16 PM

The Netduino Plus 2 has an extended Header that has separate SDA and SCL pins. Right now the firmware only supports these pins. You would need to jump to the A4/A5 pins to use older shields with the Netduino Plus 2. Chris is working on some updates to allow the firmware to be configured to use either setup, but this is too come.



Oh :) Scared me :)

#19 rgoode214

rgoode214

    Member

  • Members
  • PipPip
  • 18 posts
  • LocationSan Antonio, TX

Posted 19 December 2012 - 06:24 AM

so i touched up the solder joints and the rtc is working again on the arduino but not the netduino. Ive tried the SD/SC pins as well as analog 4 / 5 and no dice. the chipset you are using is the adafruit model which is a bit different than mine so im curious if thats the case. Its either a hardware issue or a voltage issue. When i measure the voltage on the SD or SC lines when powered from the arduino its 4.97V and on the netduino its returning 0.1v Kinda frustrating =\ Ryan

#20 rgoode214

rgoode214

    Member

  • Members
  • PipPip
  • 18 posts
  • LocationSan Antonio, TX

Posted 19 December 2012 - 08:23 AM

I tried the software I2C and was able to read the device (granted only every 3rd read was a success but that may just be the code) but id still like to figure out whats up with the hardware I2C implementation. Ryan




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.