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 Bug in 4.2


  • Please log in to reply
10 replies to this topic

#1 rhamer

rhamer

    Member

  • Members
  • PipPip
  • 29 posts
  • LocationMelbourne Australia

Posted 15 January 2012 - 11:44 PM

I have found what I believe to be a bug in the I2C code in V4.2

Im using a Netduino Plus and programming in VB.

This is the code;

Dim BytesSent As Integer

Dim con As I2CDevice.Configuration = New I2CDevice.Configuration(64 >> 1, 200)
Dim MyI2C As I2CDevice = New I2CDevice(con)

Dim data As Byte() = New Byte() {2, 255, 255}

Dim xActions As I2CDevice.I2CTransaction() = New I2CDevice.I2CTransaction() {I2CDevice.CreateWriteTransaction(data)}

BytesSent = MyI2C.Execute(xActions, 1000)

The problem is to do with the selected clock speed.

If I set the clock speed in the configuration line to 100 I get badly formatted data and that is probably because the clock is only actually running at about 95 Khz See first Attachment.

If I then change the clock to 150 I get correct data but 3 extra bytes are added to the end. See attachment 2.

Then if I use a clock speed of 200 or above I get the correct data as shown in attachment 3 and all works as expected.

I have also found that sometimes the Netduino fails to send anything at all, and I have to power cycle it to get it working again.

Can anybody explain this?

Regards

Rohan

Attached Files



#2 rhamer

rhamer

    Member

  • Members
  • PipPip
  • 29 posts
  • LocationMelbourne Australia

Posted 17 January 2012 - 12:27 AM

Is this the right place to report this? I would have thought something as important as this bug would have sparked some sort of response. Regards Rohan

#3 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 17 January 2012 - 02:59 AM

Hi Rohan, Can you please post a bug report on this over at netmf.codeplex.com and then link to it here? We can also look at the issue from our end. But let's get a bug report in so we have something to analyze it against. Chris

#4 gbreder

gbreder

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts
  • LocationGermany

Posted 23 January 2012 - 09:30 PM

I have also found that sometimes the Netduino fails to send anything at all, and I have to power cycle it to get it working again.


Hi Rohan,
no explanation from my end but I can confirm the behaviour mentioned above. Every time I fiddle with the I2C bus and one of the bus lines gets pulled from Netduino the board gets stuck and I have to power cycle it. This issue was reported a long time ago in this thread
Unplugged I2C bus stops Netduino
but the matter still persists in version 4.2.

Regards
Guido

#5 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 19 February 2012 - 02:13 AM

Any updates on this topic? Have fixes been found and put in place? I seem to be experiencing the same issue where I have multiple sensors, Real Time Clock and an LCD on I2C and occasionally the LCD gets garbled characters and occasionally the sensors report a reading of 0 (zero).

#6 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 19 February 2012 - 02:33 AM

Hmm, if it's locking up we'll want to dig into that. Can you please post a bug report on netduino.codeplex.com (and those of you experiencing it...vote on the issue)? And we'll dig into it? Chris

#7 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 19 February 2012 - 02:46 AM

Hmm, if it's locking up we'll want to dig into that. Can you please post a bug report on netduino.codeplex.com (and those of you experiencing it...vote on the issue)? And we'll dig into it?

Chris


Doesn't seem to be locking. The software is still running. I have an error log being written to the SD card and this is the exception stack:

ERROR: 02/15/2012 01:45:55 - Exception was thrown: System.IO.IOException
FusionWare.SPOT.Hardware.I2CBus::Write
FusionWare.SPOT.Hardware.I2CDeviceDriver::Write
FusionWare.SPOT.Hardware.I2CDeviceDriver::WriteReg8


#8 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 19 February 2012 - 03:45 AM

If you're seeing FusionWare.SPOT.Hardware in your stack trace, then you're using an abstraction of the I2C class... What happens if you use the I2C classes directly? If we can come up with a simple repro, we can debug from there... Chris

#9 Spork

Spork

    Advanced Member

  • Members
  • PipPipPip
  • 105 posts

Posted 13 March 2012 - 07:29 PM

If Dave is still following this thread...

FusionWare.SPOT.Hardware.I2CBus::Write code appears below. Does i2cDevice.Execute return (i.e. not throw an exception) if it times out? If so, that might be why you're seeing the System.IO.IOException (timeout happens before the specified number of bytes were written, so the test fails, and the exception is thrown).

        public void Write(I2CDevice.Configuration Config, byte[] WriteBuffer, int TimeOut)
        {
            ThrowIfDisposed();
            lock(this.Device)
            {
                this.Device.Config = Config;
                I2CDevice.I2CTransaction[] xacts = new I2CDevice.I2CTransaction[] {
                    I2CDevice.CreateWriteTransaction(WriteBuffer)
                };

                // I2CDevice.Execute returns the total number of bytes
                // transfered in BOTH directions for all transactions
                int byteCount = this.Device.Execute(xacts, TimeOut);
                if(byteCount < WriteBuffer.Length)
                    throw new System.IO.IOException();
            }
        }

Contrast with the following Write implementation from http://blog.codeblac...-with-I2C.aspx. It assumes that the timeout will sometimes occur. Instead of throwing an exception, it executes in a loop until all the bytes are written.

    private void Write(byte[] writeBuffer)
    {
        // create a write transaction containing the bytes to be written to the device
        I2CDevice.I2CTransaction[] writeTransaction = new I2CDevice.I2CTransaction[]
        {
            I2CDevice.CreateWriteTransaction(writeBuffer)
        };
 
        // write the data to the device
        int written = this.i2cDevice.Execute(writeTransaction, TransactionTimeout);
 
        while (written < writeBuffer.Length)
        {
            byte[] newBuffer = new byte[writeBuffer.Length - written];
            Array.Copy(writeBuffer, written, newBuffer, 0, newBuffer.Length);
 
            writeTransaction = new I2CDevice.I2CTransaction[]
            {
                I2CDevice.CreateWriteTransaction(newBuffer)
            };
 
            written += this.i2cDevice.Execute(writeTransaction, TransactionTimeout);
        }
 
        // make sure the data was sent
        if (written != writeBuffer.Length)
        {
            throw new Exception("Could not write to device.");
        }
    }

Maybe FusionWare.SPOT.Hardware.I2CBus::Write should do the same, but then I guess it would get stuck in an infinite loop if faced with anything other than an intermittent problem. I suppose the exception approach is better, if it's caught and dealt with somewhere appropriate up the call stack.

#10 smarcus3

smarcus3

    Advanced Member

  • Members
  • PipPipPip
  • 134 posts

Posted 12 April 2012 - 04:30 AM

I get garbled text occasionally with my LCD with I2C. Any fix for this.
Steve


My Other Hobby: Engineer Turned Baker

#11 smarcus3

smarcus3

    Advanced Member

  • Members
  • PipPipPip
  • 134 posts

Posted 12 April 2012 - 04:59 AM

I rebuilt the reference with 200 speed but it doesn't fix the garbled text after a while which makes the lcd screen go blank.
Steve


My Other Hobby: Engineer Turned Baker




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.