Netduino home hardware projects downloads community

Jump to content

The Netduino forums have been replaced by new forums at This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.


Member Since 03 Nov 2013
Offline Last Active Mar 08 2021 06:06 PM

Topics I've Started

SPI issue: bad first write

16 November 2013 - 09:23 PM


I am working on adding an spi device and only the first write after initialization appears corrupted, with subsequent writes being correct.  Perhaps I do not have the latest firmware or drivers.  Since this is simply writing, it is my understanding that it should not depend on if a device is attached.  My full code did not work, so I have reduced this to this simplest task hoping that someone might help.

Here is the code, and at the bottom are the versions of the tool chain.

Option Explicit OnOption Strict OnImports System.IOImports System.ThreadingImports System.IO.PortsImports Microsoft.SPOT'Imports Microsoft.SPOT.Hardware'Imports Microsoft.SPOT.Net.NetworkInformationImports SecretLabs.NETMF.HardwareImports SecretLabs.NETMF.Hardware.NetduinoImports Microsoft.VisualBasic.ConstantsNamespace TestADC7799    Public Module Module1        Dim _spi As SPI        Sub Main()            Debug.Print("Startup")            SetupSPI()            For j As Byte = 0 To 254                Write7799Reg(j)            Next j            Debug.Print("Finished")        End Sub        ''' <summary>        ''' Configures SPI parameters particular to ths ADC 7799        ''' </summary>        ''' <remarks></remarks>        Sub SetupSPI()            Dim _csht As UInteger = 1  ' _chipselect holdtime mS (time that CD must remain active before unselecting, or time after the read write completion)            Dim _csas As Boolean = False ' Chip select active state            Dim _csst As UInteger = 10 ' Chip select Setup Time mS (time acter cs before reading)            Dim _ce As Boolean = True  ' If true, data is sampled on the rising edge, else falling edge            Dim _cis As Boolean = True  ' click idle state, high if true            Dim _cr As UInteger = 100    ' clock frequency in kHz            Dim spiConfig As New SPI.Configuration(Pins.GPIO_PIN_D10, _csas, _csst, _csht, _cis, _ce, _cr, Microsoft.SPOT.Hardware.SPI.SPI_module.SPI1)            _spi = New SPI(spiConfig)        End Sub        Sub Write7799Reg(something As Byte)            Dim b(0) As Byte            Debug.Print("Writing Register 1 byte " & something.ToString("X"))            b(0) = something            _spi.Write(b)        End Sub    End ModuleEnd Namespace

The output window shows:

Assembly: Microsoft.VisualBasic (
Assembly: Microsoft.SPOT.Graphics (
Assembly: SecretLabs.NETMF.IO (
Assembly: SecretLabs.NETMF.Hardware.AnalogInput (
Assembly: SecretLabs.NETMF.Hardware (
MFDeploy reports:

Pinging... TinyCLR


HalSystemInfo.halVendorInfo:   Netduino Plus 2 (v4.2.2.2) by Secret Labs LLC

HalSystemInfo.oemCode:   34

HalSystemInfo.modelCode:   177


The logic analyzer shows that the initial idle state of the CLK line does not match the settings.


My code is attached.




Read problems from SD Card

12 November 2013 - 06:52 PM

Hi All:


I have been having mixed success with SD.   I can usually write to the SD card, and read the contents in my PC.  However, when I execute the code below, it will ALWAYS crash during the read segment (ReadFile).  It always crashed with this being displayed in the debug window: A first chance exception of type 'System.IndexOutOfRangeException' occurred in System.IO.dll

Error in ReadFile; Exception was thrown: System.IndexOutOfRangeException
This may happen after 78 lines read, or after as many as 778 reads, or various numbers in between.


I am using the latest 4.2 firmware, Visual Studio 2012 Pro, Visual Basic, NetFramework 4.2.

I am using a SanDisk 128MB microSD card.


As this fails after different number of reads, perhaps the hardware is bad.  On this assumption I ordered another Netduino Plus 2 which I will try tonight. 


I see in the forums that there seem to be quite a bit of problems with the SD card.  If anyone has any suggestion on how to resolve this, please comment!  


Thanks .  


Imports System.netImports System.Net.SocketsImports System.IOImports System.TextImports System.ThreadingImports System.IO.PortsImports Microsoft.SPOTImports Microsoft.SPOT.HardwareImports Microsoft.SPOT.Net.NetworkInformationImports Microsoft.SPOT.IOImports SecretLabs.NETMF.HardwareImports SecretLabs.NETMF.Hardware.NetduinoImports Microsoft.VisualBasic.ConstantsNamespace CFcardUsage    Public Module Module1        Dim cardPresent As Boolean = True        Sub Main()            ' eject handler suggested by Stephan at            AddHandler SPOT.IO.RemovableMedia.Eject, AddressOf RemovableMedia_Eject            AddHandler Microsoft.SPOT.IO.RemovableMedia.Insert, AddressOf RemovableMedia_Insert            Debug.Print("Startup CF Card Usage")            ' Define path and filename            Dim strPath As String = "SD" & DateTime.Now.ToString("yyyyMM")            Dim strFileName As String = strPath & "" & DateTime.Now.ToString("yyyyMMdd") & ".log"            ' make sure disk is there and create directory if needed            Try                If Not File.Exists(strFileName) Then ' ** This shows a AND the following line executes, also throwing an exception                    If Not Directory.Exists(strPath) Then '** This also shows a System.IO.IOexception in debugger, and the following line executes                        Directory.CreateDirectory(strPath) ' ** the exception appears to be thrown her and goes to the catch                    End If                End If            Catch ex As Exception                Debug.Print("Exception thrown - " & ex.Message)                Debug.Print("Presumably there is no readable card present")                cardPresent = False            End Try            ' if no card is found, wait for one to be inserted            Do While True                If cardPresent Then Exit Do                Debug.Print("insert card")                Threading.Thread.Sleep(1000)            Loop            Debug.Print(strFileName)            ' open the streamwriter            Dim sw As StreamWriter = New StreamWriter(File.OpenWrite(strFileName))            sw.WriteLine("This is to write the files to the netduino card")            'lets learn how fast we can write to these cards            Dim StartTime As DateTime = DateTime.Now            Dim excp As Boolean = False            For i As Integer = 0 To 10000                Dim t As String = DateTime.Now.ToString                Dim EndTime As TimeSpan = DateTime.Now.Subtract(StartTime)                Try  ' if this fails, lets get the error, and stop writing so I can see if prior data is ok                    sw.Write("Memory usage " & Microsoft.SPOT.Debug.GC(False).ToString & "; Elapsed time " & EndTime.Seconds.ToString & "." & EndTime.Milliseconds.ToString)                    sw.WriteLine("; line number " & i.ToString & " at " & t & ", ms counter = " & DateTime.Now.Millisecond.ToString & ", tics= " & DateTime.Now.Ticks.ToString & ", machine time " & Hardware.Utility.GetMachineTime.Ticks.ToString)                Catch ex As Exception                    Debug.Print("Exception " & ex.Message & ", at i=" & i.ToString & ", ET= " & EndTime.ToString)                    ' exit the write loop                    Exit For                End Try                If i Mod 1000 = 0 Then Debug.Print(i.ToString)            Next            ' try everything possible to make sure the writes are complete to the card            sw.Flush()            sw.BaseStream.Flush()            sw.BaseStream.Close()            sw.Dispose()            ' if there was a write error, just exit, otherwise read back the contents            If Not excp Then ReadFile(strFileName)        End Sub        Sub ReadFile(filename As String)            ' this will read and display the contents of the card.            If File.Exists(filename) = False Then                Debug.Print("File does not exist")                Return            End If            Dim sr As StreamReader = New StreamReader(filename)            Dim s As String = ""            Do                Try                    s = sr.ReadLine() ' crashes with index out of range exception ( after some number of reads                Catch ex As Exception ' must use a try/catch or file will be deleted or not found. Does not seen to always work                    Debug.Print("Error in ReadFile; " & ex.Message)                    Exit Do                End Try                Debug.Print("Mem now: " & Microsoft.SPOT.Debug.GC(False).ToString & "; Recorded data: " & s)            Loop Until sr.EndOfStream            Debug.Print("Last line read was: " & s)            sr.Close()            sr.Dispose()        End Sub        Sub RemovableMedia_Eject(sender As Object, e As Microsoft.SPOT.IO.MediaEventArgs)            Debug.Print("Ejected")            cardPresent = False        End Sub        Sub RemovableMedia_Insert(sender As Object, e As Microsoft.SPOT.IO.MediaEventArgs)            Debug.Print("Inserted or present")            cardPresent = True        End Sub    End ModuleEnd Namespace


Trying to determine if I should reflash NP2

07 November 2013 - 08:29 PM


I am just getting started with the NP2, and after several successful "blink-the-LED" efforts I switched to try the PWM functions, and started getting compile warnings (overflow will not throw exception), I was unable to reprogram the device. 

I tried the deployment tool, and find that while I can ping the device and get back the following:

Pinging... IP Address:
No debugger!
Create TS.
 Loading start at 806a988, end 8085288
Assembly: mscorlib (
Assembly: Microsoft.SPOT.Native (
Assembly: Microsoft.SPOT.Hardware (
Assembly: Microsoft.SPOT.Net (
Assembly: System (
Assembly: Microsoft.SPOT.Hardware.SerialPort (
Assembly: Microsoft.SPOT.IO (
Assembly: System.IO (
Assembly: Microsoft.SPOT.Hardware.PWM (
Assembly: Microsoft.SPOT.Hardware.Usb (
Assembly: SecretLabs.NETMF.Diagnosti
After I get this, if I re-ping, there is no response.  Also, if I disconnect and reconnect (unplug/plug) I get the same response.  Please note it always fails to complete the line: "Assembly: SecretLabs.NETMF.Diagnosti" and I do not know if there should be more lines. 
I am not sure what I should do next.  Perhaps erase the device and reload?  If so, is there a procedure with locations of the necessary files specified?
Running Win8.0/32 on an old laptop.  The target framework is .NET Micro Framework 4.2. Using Visual Studio 2012 pro and VB.  

Can't get past go

03 November 2013 - 12:45 AM

I just purchased a netduino plus 2, but can't get past go...

I have installed .NET Micro Framework 4.3 (RTM)
Visual studio is Premimum 2012, 11.0.60610.01 Update 3
Windows 8.1/64 (all updates applied)
Start visual studio, select from templates Netduino Plus 2 application, 
then go to My Project, and select .NET Micro Framework, the PC will immediately crash (blue screen) with a Bad_pool_header and proceed to reboot.
This happens if I select VB or C#.
This happens with both framework 4.2 and 4.3.
This happens with the board both connencted and disconnected
I have not entered any code, just picked a template.
No other programs are running, and this is completely reproducible.
The only thing slightly unusual about my setup is that the development tools are not on C: but another drive (O:). I have not problems developing in VB.NET.
Any suggestions are appreciated as I have no idea what to do next.
Thanks for your help

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.