Max72197221 ExtendedSpiConfiguration NullReferenceException

Jul 30, 2012 at 8:38 PM
Edited Jul 30, 2012 at 8:42 PM

I'm attempting to test and implement the Max72197221 from the netduinohelpers-e0ddb8758a93 in a project or two experimenting with 7segment displays and an 8x8 matrix. 

I'm working with the Max72197221Test project from the Samples directory.  

I'm getting a NullReferenceException on this line (92) in the ExtendedSpiConfiguration class

            fieldInfo.SetValue(this, BitsPerTransfer);
My .netmf and netduino sdk Netduino SDK v4.1.0 (November 2010 Refresh), Secret Labs LLC Product version: 4.1.0001, Microsoft .NET Micro Framework SDK 4.1 (QFE1) v 4.1.2821.0
The Debug output:

Rebooting...
Found debugger!
Create TS.
 Loading start at 1381c8, end 14b204
Attaching file.
Assembly: mscorlib (4.1.2821.0) (3880 RAM - 33236 ROM - 19134 METADATA)

Attaching file.
Assembly: Microsoft.SPOT.Native (4.1.2821.0) (1144 RAM - 6516 ROM - 4479 METADATA)

Attaching file.
Assembly: Microsoft.SPOT.Hardware (4.1.2821.0) (1752 RAM - 11440 ROM - 7371 METADATA)

Attaching file.
Assembly: Microsoft.SPOT.Hardware.SerialPort (4.1.2821.0) (512 RAM - 3488 ROM - 1543 METADATA)

Attaching file.
Assembly: Microsoft.SPOT.IO (4.1.2821.0) (740 RAM - 4620 ROM - 2522 METADATA)

Attaching file.
Assembly: System.IO (4.1.2821.0) (1548 RAM - 13292 ROM - 5862 METADATA)

Attaching file.
Assembly: Microsoft.SPOT.Hardware.Usb (4.1.2821.0) (580 RAM - 3740 ROM - 1844 METADATA)

Attaching file.
Assembly: SecretLabs.NETMF.Hardware (4.1.0.0) (256 RAM - 1108 ROM - 491 METADATA)

Attaching file.
Assembly: SecretLabs.NETMF.Diagnostics (4.1.0.0) (180 RAM - 440 ROM - 166 METADATA)

Loading Deployment Assemblies.
Attaching deployed file.
Assembly: SecretLabs.NETMF.Hardware.Netduino (4.1.0.0) (268 RAM - 796 ROM - 423 METADATA)

Attaching deployed file.
Assembly: Max7219CodePlexDemo (1.0.0.0) (556 RAM - 4536 ROM - 1601 METADATA)

Resolving.

Total: (9868 RAM - 83212 ROM - 45436 METADATA)


Total: (9868 RAM - 83212 ROM - 45436 METADATA)

The debugging target runtime is loading the application assemblies and starting execution.Ready.
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.1\Assemblies\le\mscorlib.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.1\Assemblies\le\Microsoft.SPOT.Native.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.1\Assemblies\le\Microsoft.SPOT.Hardware.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.1\Assemblies\le\Microsoft.SPOT.Hardware.SerialPort.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.1\Assemblies\le\Microsoft.SPOT.IO.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.1\Assemblies\le\System.IO.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.1\Assemblies\le\Microsoft.SPOT.Hardware.Usb.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Secret Labs\Netduino SDK\Assemblies\v4.1\le\SecretLabs.NETMF.Hardware.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'SecretLabs.NETMF.Diagnostics''Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:\Program Files (x86)\Secret Labs\Netduino SDK\Assemblies\v4.1\le\SecretLabs.NETMF.Hardware.Netduino.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'c:\users\jeffa\documents\visual studio 2010\Projects\Max7219CodePlexDemo\Max7219CodePlexDemo\bin\Debug\le\Max7219CodePlexDemo.exe', Symbols loaded.The thread '<No Name>' (0x2) has exited with code 0 (0x0).    #### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (1) ####    #### Message:     #### Max7219CodePlexDemo.ExtendedSpiConfiguration::.ctor [IP: 004d] ####    #### Max7219CodePlexDemo.ExtendedSpiConfiguration::.ctor [IP: 0015] ####    #### Max7219CodePlexDemo.Max72197221::.ctor [IP: 0031] ####    #### Max7219CodePlexDemo.Program::Main [IP: 001d] ####A first chance exception of type 'System.NullReferenceException' occurred in Max7219CodePlexDemo.exeAn unhandled exception of type 'System.NullReferenceException' occurred in Max7219CodePlexDemo.exe

Coordinator
Jul 31, 2012 at 12:39 AM
Edited Jul 31, 2012 at 12:40 AM

Hi Jeff,

You can ditch the extended config and use a regular SPI initialization like this:

 

        public Max72197221(Cpu.Pin chipSelect, SPI.SPI_module spiModule = SPI.SPI_module.SPI1, uint speedKHz = (uint)10000) {
            var spiConfig = new SPI.Configuration(
                SPI_mod: spiModule,
                ChipSelect_Port: chipSelect,
                ChipSelect_ActiveState: false,
                ChipSelect_SetupTime: 0,
                ChipSelect_HoldTime: 0,
                Clock_IdleState: false,
                Clock_Edge: true,
                Clock_RateKHz: speedKHz);
            Spi = new SPI(spiConfig);
            DigitScanLimitSafety = true;
            SpiBuffer = new ushort[1];
        }
Also, I recommend controlling the power to the Max7219 separately from the Netduino power using a PNP transistor, only powering the Max once your C# application is running. You may want to read this article http://channel9.msdn.com/coding4fun/articles/What-Is-an-Arduino-Shield-and-Why-Should-My-Netduino-Care to discover why that is. Cheers, -Fabien.
Aug 4, 2012 at 8:46 PM
Edited Aug 4, 2012 at 8:49 PM

Would you like me to file a bug report so the constructor in Max72197221 sample will be updated? 

From the pastebin you sent me via twitter? http://pastebin.com/9q6zHwev

        public Max72197221(
		Cpu.Pin chipSelect, 
		SPI.SPI_module spiModule = SPI.SPI_module.SPI1,
		uint speedKHz = (uint)10000) {
            var spiConfig = new SPI.Configuration(
                SPI_mod: spiModule,
                ChipSelect_Port: chipSelect,
                ChipSelect_ActiveState: false,
                ChipSelect_SetupTime: 0,
                ChipSelect_HoldTime: 0,
                Clock_IdleState: false,
                Clock_Edge: true,
                Clock_RateKHz: speedKHz);
            Spi = new SPI(spiConfig);
            DigitScanLimitSafety = true;
            SpiBuffer = new ushort[1];
        }

Coordinator
Aug 4, 2012 at 8:56 PM
Edited Aug 4, 2012 at 8:56 PM

Here's the thing: there's no bug here. ExtendedSpiConfiguration is proven to work on Netduino firmware v4.1.1 and above. Have you checked out the netduino.com forums for any known issues with ExtendedSpiConfiguration on other firmware versions since Secret Labs provides this class?

Aug 4, 2012 at 11:04 PM

Ahh, OK I deployed this to get the firmware version information. Looks like I'm running a version less than v4.1.1

            Debug.Print("Systeminfo .Version, .SystemID.Model, OEMString: " +
                SystemInfo.Version + ", " + SystemInfo.SystemID.Model + ", " + SystemInfo.OEMString);

Which displays: "Systeminfo .Version, .SystemID.Model, OEMString: 4.1.0.6, 0, Netduino by Secret Labs LLC"

I'm not liking the display from the test. I previously had DIG and SEG reversed. I've tested with some Arduino code and I can now address each row and column correctly. With the netmf test code I'm now getting close but no cigar yet.

I'll go attempt to upgrade my Netduino firmware. I noticed there are some bug fixes to SPI in the v4.2 release notes.