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")); } } } }}