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

SPI and I2CDevice not working together


  • Please log in to reply
7 replies to this topic

#1 Steph

Steph

    Member

  • Members
  • PipPip
  • 16 posts

Posted 08 March 2013 - 05:34 PM

In Netduino Plus (NETMF 4.2) I get an Exception Error as soon as I add both SPI and I2C devices to my application

( I get the exceprion error when I step into the initialization line of the second device ).

 

In two seperate programs the SPI (ST RTC - M41T94) and I2C (TI Temp Sensor - TMP101) devices are woking fine with no problems.

 

Why is this happening and what can I do to solve this problem?

 

Thanks for the help.

 

 

 



#2 Gutworks

Gutworks

    Advanced Member

  • Members
  • PipPipPip
  • 363 posts
  • LocationOttawa, Ontario

Posted 09 March 2013 - 04:44 PM

Hi Steph,

 

Can you provide a short code sample that generates the error? I have yet to try SPI and I2C together and wouldn't mind trying to replicate it. 

 

Cheers,

Steve



#3 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 09 March 2013 - 04:58 PM

i used both together and it worked fine. (different devices, but spi and i2c, each with multiple devices)

 

add some code so we can have a look, wild guessing is no fun :(



#4 Steph

Steph

    Member

  • Members
  • PipPip
  • 16 posts

Posted 11 March 2013 - 06:58 PM

Hi NooM,

I've added some code below. As said before, both projects compile and run successfully (seperately), but when I add the code together I get the following error in VS2010 when I step into - "I2CDevice TMP101 = new I2CDevice(new I2CDevice.Configuration(0x48, 400));"

 

"An unhandled exception of type 'System.InvalidOperationException' occurred in Microsoft.SPOT.Hardware.dll"

 

My board resembles a NDPlus, but without the ethernet. Hence I recompiled the firmware with (RVDS4.1) after I removed the networking functions using Solution Wizard. (I've been running and testing a lot of code for the last few weeks without any major issues...).  

I also updated and recompiled C:NetduinoSDKSourceSecretLabs.NETMF.Hardware.NetduinoPlusNetduinoPlusHardwareProvider.cs I then manually copied and overwrite the new .dll's to:

 

C:Program Files (x86)Secret LabsNetduino SDKAssembliesv4.2  ...be  and ...le folders respectively. (Is it ok to do it like that...?)

 

The code below is my RTC_App with I2C code added. The Class_RTC mainly declares a new SPI device: "static SPI.Configuration spi_RTC_M41T94 = new SPI.Configuration(Pins.GB_SPI0_CS3, false, 1, 1, true, true, 500, SPI_Devices.SPI1);" "static SPI RTC_M41T94 = new SPI(spi_RTC_M41T94);"

and update the system time when I get the interrupt - "Utility.SetLocalTime(dt);"

The "Pins.GB_RTC_IRQ" is declared at PB26 (previously Ethernet IRQ)

 

I apreciate the help.

 

 

namespace NetduinoPlus_RTC_App{    public class Program    {        static Class_RTC stRTC = new Class_RTC();        static bool bflag_SecFlag = true;        public static void IrqRTC_OnInterrupt(uint port, uint state, DateTime time)        {            stRTC.CaptureRtcTime();            bflag_SecFlag = true;        }        //-------------------------------------------------------------------------------------------        public static void Main()        {            InterruptPort IrqRTC = new InterruptPort(Pins.GB_RTC_IRQ, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);            IrqRTC.OnInterrupt += new NativeEventHandler(IrqRTC_OnInterrupt);            //----- I2C Temperature Code ------------            byte[] TxBuffer = new byte[4];            byte[] RxBuffer = new byte[8];            int Tempreg;            float Temperature = 0;            I2CDevice TMP101 = new I2CDevice(new I2CDevice.Configuration(0x48, 400));            I2CDevice.I2CTransaction[] TMP101_write = new I2CDevice.I2CTransaction[]            {                I2CDevice.CreateWriteTransaction(new byte[]{0x01,0x60})            };            I2CDevice.I2CTransaction[] TMP101_read = new I2CDevice.I2CTransaction[]            {                I2CDevice.CreateWriteTransaction(new Byte[1]{0x00}),                I2CDevice.CreateReadTransaction(RxBuffer)            };            TMP101.Execute(TMP101_write, 500);            TMP101.Execute(TMP101_read, 500);            //---------------------------------------            stRTC.Initialize_RTC();            stRTC.EnableAlarm();            while (true)            {                Thread.Sleep(2);                if( bflag_SecFlag == true )                {   bflag_SecFlag = false;                    //---- Print the current Temperature ----                    TMP101.Execute(TMP101_read, 500);                    Tempreg = RxBuffer[0];                    Tempreg <<= 8;                    Tempreg |= RxBuffer[1];                    Tempreg >>= 4;                    Temperature = (float)Tempreg / 16;                    Debug.Print("Temp - " + Temperature.ToString("F1"));                    //---------------------------------------                    Debug.Print("Time - " + DateTime.Now.ToString("HH:mm:ss"));                }            }        }    }}


#5 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 11 March 2013 - 08:27 PM

As said before, both projects compile and run successfully (seperately), but when I add the code together I get the following error...

  When you added the projects together, did you make any additional modifications? Like changing pin numbers? Or does the error occur after you add exactly the same (unmodified) code?  

"An unhandled exception of type 'System.InvalidOperationException' occurred in Microsoft.SPOT.Hardware.dll"   My board resembles a NDPlus, but without the ethernet. Hence I recompiled the firmware with (RVDS4.1) after I removed the networking functions using Solution Wizard. (I've been running and testing a lot of code for the last few weeks without any major issues...).

  Well, it will not be easy to troubleshoot such issue without detailed knowledge of all your changes, but I would suspect wrong pin configuration - incorrect pin number, not initialized properly or being used already by different peripheral or something like that. I assume you don't have JTAG on your board (?), so in that case I would locate code blocks that return CLR_E_INVALID_OPERATION and are related to I2C, SPI or pin reservation and place some diagnostic output there (there are not so many of them in the firmware).

#6 Steph

Steph

    Member

  • Members
  • PipPip
  • 16 posts

Posted 14 March 2013 - 06:26 AM

Hi CW2,

 

No, I've tested the code as is (with exactly the same pin numbers) and absolutely no other modifications. The initialization code from.. " //----- I2C Temperature Code ------------" is exactly the same as in the stand-alone app, where it works 100%.

 

I do have jtag pins to a header and I do have an Atmel SAM-ICE, but I'm not sure how to debug the SDK source :(

 

Somewhere I saw that Chris mentioned that they use the ARM IDE to debug SDK...?

How will I start, debug and run my .NETMF app from another IDE other than VS2010?

 

Regards



#7 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 14 March 2013 - 01:33 PM

in my signature is a link to my playground, you can find a multi i2c and multi spi class there. and a simple rtc (ds1307) class that shows the usage of the multi i2c (spi is very simmiliar to use!)



#8 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 14 March 2013 - 02:17 PM

Hi Steph,<br /><br />I don't know what pins and resources the classes are using in the support classes, but can you double-check that your two classes aren't trying to reserve or use the same GPIO pins?<br /><br />One of the first things I do to debug in a scenario like this is double-check which resources each class requires. If there is a pin, bus, etc. used by both and they're not designed to share...exceptions will happen.<br /><br />Also, if you can step into your second class and see what line of code is actually causing the exception...that will help in diagnostics.<br /><br />Finally--you can debug the native firmware via JTAG. You'll need to build the firmware in debug mode and then attach via the MiniJTAG header. But I'd recommend that you start bug hunting on the managed code side first.<br /><br />Chris




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.