Has someone got this to work on the N+2?
Fails in this line:
private I2CDevice clock = new I2CDevice(new I2CDevice.Configuration(I2CAddress, I2CClockRateKhz));
System.InvalidOperationException

  | ||||||||||||||
DS1307 Real Time Clock
Started by stacyh3, Aug 26 2010 10:15 PM
41 replies to this topic
#21Posted 17 February 2013 - 09:09 AM Has someone got this to work on the N+2?
Fails in this line:
private I2CDevice clock = new I2CDevice(new I2CDevice.Configuration(I2CAddress, I2CClockRateKhz));
System.InvalidOperationException #22Posted 17 February 2013 - 12:29 PM
I have several of the adafruit ones working with several ND+2. Need much more info. What address and speed are your setting. How is it wired?
#23Posted 17 February 2013 - 05:13 PM Hi Dave,
Yes, the problem might be the address and speed as you pointed out. This is the code I am using which I got it from this thread posted by stacyh3 and got it to work only in the N+:
private const int I2CAddress = 0x68; private const int I2CTimeout = 1000; private const int I2CClockRateKhz = 100; public const int UserDataAddress = 8; public const int UserDataLength = 56;
Of course I connected to the SC and SD ports respectivelly in the N+2, not the A4 and A5 Analog ports, and here is the device capabilities:
HalSystemInfo.halVersion: 4.2.0.0 HalSystemInfo.halVendorInfo: Netduino Plus 2 (v4.2.2.2) by Secret Labs LLC HalSystemInfo.oemCode: 34 HalSystemInfo.modelCode: 177 HalSystemInfo.skuCode: 4102 HalSystemInfo.moduleSerialNumber: 00000000000000000000000000000000 HalSystemInfo.systemSerialNumber: 0000000000000000 ClrInfo.clrVersion: 4.2.0.0 ClrInfo.clrVendorInfo: Netduino Plus 2 (v4.2.2.2) by Secret Labs LLC ClrInfo.targetFrameworkVersion: 4.2.0.0 SolutionReleaseInfo.solutionVersion: 4.2.2.2 SolutionReleaseInfo.solutionVendorInfo: Netduino Plus 2 (v4.2.2.2) by Secret Labs LLC SoftwareVersion.BuildDate: Jan 26 2013 SoftwareVersion.CompilerVersion: 410894 #24Posted 17 February 2013 - 06:33 PM Hi Dave,
I got rid of that code and use the Toolbox.NETMF.Hardware.DS1307 class instead and worked like a charm by itself but seems to be conflicting with the drivers for the Hd44780 Lcd if I put the code all together.
I'll keep you posted of my findings on why the LCD drivers are conflicting. #25Posted 17 February 2013 - 10:28 PM What drivers are you using for the LCD? Is this an I2C based backpack of some type to drive it or are you using SPI? #26Posted 17 February 2013 - 10:47 PM Hi Dave,
Yes, I am using the backpack you recommended me a while ago and using SPI and the code is pretty much the same as posted below with the difference that the project I am running is for N+2:
http://forums.netdui...cd-for-n/page-2
If I instantiate the _bus variable lile this:
_bus = new I2CBus();
at the beginning of the program, then this line crashes:
dS1307 = new DS1307();
To be more specific this line if I step into:
_I2CDevice = new I2CDevice(this._Configuration);
Throwing this error:
"Exception was thrown: System.InvalidOperationException"
However if I comment out the instantiation of the _bus variable, then the instantiation of dS1307 runs just fine.
Any clues what could be causing this issues? Maybe I cannot use the LCD in SPI mode when using the SDA and SCL ports?
Thanks #27Posted 18 February 2013 - 12:26 AM Here is the project that re-creates the issue I am experiencing. Attached Files#28Posted 18 February 2013 - 12:56 PM I'll download the code later today try it on the bench. I have a ND+2 with RTC1307 and an I2C/SPI backpack test rig.
First thing I would recommend is upgrading the Firmware. Looks like you are still on 4.2.1.0 and there were SPI Changes made in the versions following that. Latest is 4.2.2.2. #29Posted 18 February 2013 - 10:03 PM Thanks Dave, I appreciate your help on this. By the way I open MFDeploy and this is what I got in Device Capabilities:
Question, would the .NET MF Toolbox (http://netmftoolbox.codeplex.com/) work with the i2c / SPI character LCD backpack I have? #30Posted 21 February 2013 - 06:43 PM I am getting the same failure as you using your setup and code. I'll try to debug through it and post my findings in a little while. #31Posted 21 February 2013 - 07:14 PM So, it looks like the issue is that you don't need to create the instance of I2CBus when you are using the MultiI2C. I am using a different Multiple I2C provider so my initializeLCD method was being passed that bus. Since you are using SPI for the LCD and not I2C you should be fine. You need to make the following changes.
Remove the Lines: private static I2CBus _bus; and _bus = new I2CBus(); Then change the initializeLCD Method from: private static void initializeLCD(I2CBus bus){} To (so you are not passing the I2CBus) private static void initializeLCD(){} Then change the initializeLCD(_bus); To initializeLCD(); Finally, you may want to add the second line of code below to sync the Netduino's time to the DS1307 each time the ND+2 is started dS1307 = new DS1307();dS1307.Synchronize(); The MultiI2C should handle it all from here forward. Just remember any I2C Device Drivers you get off the internet, Netduino forums or other developers may use various means of handing I2C and you may need to change the Class' constructor to handle MultiI2C for your needs.
After I made these changes I was able to use both the DS1307 and the LCD together. I rebooted the Netduino Plus 2 several times to ensure that it would sync the time each time.
PS: Is you want to give it a good workout after the changes add this method to make it a clock pulling from the DS1307 each time. while (true){ LCD.Print(Lcd.Position.ROW_4, Lcd.Position.COLUMN_1, Lcd.FillRow(dS1307.GetTime().ToString())); Thread.Sleep(10);} #32Posted 21 February 2013 - 08:19 PM Thank you so much Dave for getting back to me an explaining what the issue was in such much detail. I really appreciate it. #33Posted 22 July 2013 - 09:40 AM The attached zip files doesnt work. Any instructions how to open it properly? Thanks #34Posted 13 December 2013 - 07:39 PM Which code is not working, the one from stacyh3 or mine?
Did you install the .NET Micro Framework for Visual Studio 2010 or Visual Web Express 2010?
Thanks #35Posted 16 December 2013 - 07:42 PM If it is of any help, I have a blog post on hooking up the DS1307 with some code.
http://christianlori...ttle-soldering/
#36Posted 16 December 2013 - 08:10 PM Another example here on youtube: Netduino RealTimeClock Library Tutorial: http://www.youtube.c...h?v=ePT2Q0C5aBY #37Posted 22 December 2013 - 02:12 PM Hi. First post to this forum - hope you can help? I'm a bit new to all of this so apologies if this is a daft question:
Trying to get this code working on a Netduino Plus 2 on framework v4.2. I'm getting a runtime error when I get to the line coloured in red below. public class DS1307RealTimeClock : IDisposable { private const int I2CAddress = 0x68; private const int I2CTimeout = 1000; private const int I2CClockRateKhz = 100; public const int UserDataAddress = 8; public const int UserDataLength = 56; private I2CDevice clock = new I2CDevice(new I2CDevice.Configuration(I2CAddress, I2CClockRateKhz)); /// <summary> /// Set the local .NET time from the RTC board. You can do this on startup then call /// DateTime.Now during program execution. /// </summary> public void SetLocalTimeFromRTC() { var dt = Now(); Utility.SetLocalTime(dt); } The error states:
[font="'courier new', courier, monospace;"]Locating source for 'C:DocumentsSecret LabsProjectsProductionSecretLabs.NETMF.Hardware.NetduinoNetduinoHardwareProvider.cs'. Checksum: MD5 {9a 41 9e 8d e1 47 28 af 1a ec 47 39 bb 46 2 8b}[/font] [font="'courier new', courier, monospace;"]The file 'C:DocumentsSecret LabsProjectsProductionSecretLabs.NETMF.Hardware.NetduinoNetduinoHardwareProvider.cs' does not exist.[/font] Sure enough, I don't have that file on my disk - so how do I go about resolving this please? Regards, Matthew
#38Posted 23 December 2013 - 11:56 PM
Hi Matthew,
It sounds like you're trying to step into the firmware source code. You can grab it from the Downloads page--but "stepping over" rather than "stepping into" the code should also fix this issue for you.
Chris
#39Posted 23 January 2014 - 02:32 PM Still can't get the DateTime.Now... it's return 2002/01/01 00:00:00
I'm using RTC from Seed Studio. the configuration below:
SDA -- > R 4.7k --> Vcc (5v) SCL --> R 4.7 k --> Vcc
should I breakout the Pull Up resistor from Vcc to 3.3V battery? to make this code works?
#40Posted 23 January 2014 - 02:59 PM what a silly...
I just Run this code // TODO: Do this only once to set your clock//clock.SetClock(10, 8, 26, 17, 45, 30, DayOfWeek.Wednesday); then It's work.....
so I need to set the clock at the first time. umm
is there any way for me to get the Clock from my PC? 2 user(s) are reading this topic0 members, 1 guests, 0 anonymous users
| ||||||||||||||
|
||||||||||||||
This webpage is licensed under a Creative Commons Attribution-ShareAlike License. | ||||||||||||||