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 protocol


  • Please log in to reply
8 replies to this topic

#1 stacyh3

stacyh3

    Advanced Member

  • Members
  • PipPipPip
  • 47 posts

Posted 18 August 2010 - 03:37 PM

I've been working with the DS1307 Real Time Clock mounted on the SparkFun breakout board. In reading data from the clock, I am able to use the following code successfully:

            // Go to address zero.
            transaction = new I2CDevice.I2CTransaction[]
            {
                I2CDevice.CreateWriteTransaction(new byte[] {0})
            };

            result = clock.Execute(transaction, i2c_timeout);

            // Read data
            var data = new byte[7];
            transaction = new I2CDevice.I2CTransaction[]
            {
                I2CDevice.CreateReadTransaction(data)
            };

            result = clock.Execute(transaction, i2c_timeout);

It appears that you should be able to do something like this:

            // Read data
            var data = new byte[7];
            transaction = new I2CDevice.I2CTransaction[]
            {
                I2CDevice.CreateWriteTransaction(new byte[] {0}),
                I2CDevice.CreateReadTransaction(data)
            };

            result = clock.Execute(transaction, i2c_timeout);

This would combine the write to the clock to set the address and the read to get the data. This causes the netduino to freeze and requires me to unplug the clock and erase the netduino code. I'm okay with doing this in two steps, I'm just curious if it's "supposed" to work in one combined transaction.

Thanks!

Stacy

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 18 August 2010 - 04:29 PM

I'm okay with doing this in two steps, I'm just curious if it's "supposed" to work in one combined transaction.


Very curious. It should work as a single step (and in fact, that's the preferred way to do it with I2C). We tested the RTC on the Adafruit Datalogger shield using the I2C feature similarly and it worked well... We'll get one of these in the lab and run it through the logic analyzer and debugger to see what's going on :)

Is this the board you're using?

Chris

#3 stacyh3

stacyh3

    Advanced Member

  • Members
  • PipPipPip
  • 47 posts

Posted 18 August 2010 - 05:27 PM

Very curious. It should work as a single step (and in fact, that's the preferred way to do it with I2C). We tested the RTC on the Adafruit Datalogger shield using the I2C feature similarly and it worked well... We'll get one of these in the lab and run it through the logic analyzer and debugger to see what's going on :)

Is this the board you're using?

Chris

Yes, that's the board. And I am using the latest netduino firmware with the analog fixes. It almost feels like a timing issue. Like the read may be happening to quickly after the write. of course, that's just a gut feel, since things seem to work fine when I separate the calls.

My connection are 5V and ground as indicated. SCL to Analog 5, and SDA to Analog 4.

Thanks! Let me know if there's any further debugging I can do.

Stacy

#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 18 August 2010 - 05:44 PM

Okay, I just ordered one from SparkFun. We should receive it by early next week. I'll let you know what we find :) Thanks for the feedback, Stacy.

#5 stacyh3

stacyh3

    Advanced Member

  • Members
  • PipPipPip
  • 47 posts

Posted 19 August 2010 - 04:52 PM

I think I may have found my issue. One of my pull-up resistors was not connected corectly. I usually double check my hardware connections since I'm a hardware novice, but I missed this. Thanks to a magnifying glass, I found the issue. Now the RTC chip is responding reliably every time and I can combine I2C read and write transactions. Yay! I'll keep testing to make sure that there wasn't some other anomaly. Thanks, Stacy

#6 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 19 August 2010 - 05:05 PM

I think I may have found my issue. One of my pull-up resistors was not connected corectly. I usually double check my hardware connections since I'm a hardware novice, but I missed this. Thanks to a magnifying glass, I found the issue. Now the RTC chip is responding reliably every time and I can combine I2C read and write transactions. Yay!

I'll keep testing to make sure that there wasn't some other anomaly.


Stacy, thanks for the update. I'll take this off our priority queue...but if you run into any I2C glitches please let us know!

Chris

#7 greg

greg

    Advanced Member

  • Members
  • PipPipPip
  • 169 posts
  • LocationChicago, IL

Posted 25 August 2010 - 02:09 AM

Stacy, Care to post your code and diagram? I'm just starting to work with the DS1307 as well and having some trouble understanding I2C stuff so this would be a big help. Thanks!

#8 stacyh3

stacyh3

    Advanced Member

  • Members
  • PipPipPip
  • 47 posts

Posted 25 August 2010 - 01:26 PM

I can post the code later today. Eventually this will be part of a larger project that I'll also share with the community. It's still pretty rough at this point, but it does work :) Stacy

#9 stacyh3

stacyh3

    Advanced Member

  • Members
  • PipPipPip
  • 47 posts

Posted 27 August 2010 - 12:34 AM

I can post the code later today. Eventually this will be part of a larger project that I'll also share with the community. It's still pretty rough at this point, but it does work :)

Stacy


The code is posted in the projects section.

Stacy




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.