- Netduino Forums
- → Blake Ramsdell's Content
Blake Ramsdell's Content
There have been 8 items by Blake Ramsdell (Search limited from 04-June 23)
#7325 NETMF constants
Posted by Blake Ramsdell on 09 January 2011 - 09:26 AM in General Discussion
I'm mulling what to do about the digital input mappings, but for the SPI devices, can I just use SPI.SPI_module.SPI1 instead of the Netduino version? They're the same value (0).
#7358 NETMF constants
Posted by Blake Ramsdell on 09 January 2011 - 08:44 PM in General Discussion
Yes, absolutely. We made sure to follow the .NET MF best practices...so you can swap in (Cpu.Pin) and (SPI.SPI_module) instead of the Netduino constants. This will also make your code portable across Netduino Mini, AUG, Device Solutions, custom boards, etc.
This is where I'm confused -- why are there Netduino-specific constants for NETMF-provided constructs? That is, I see:
namespace SecretLabs.NETMF.Hardware.Netduino { public static class SPI_Devices { public const SPI.SPI_module SPI1 = 0; } }
and I see:
namespace Microsoft.SPOT.Hardware { public sealed class SPI : IDisposable { ... public enum SPI_module { SPI1 = 0, SPI2 = 1, SPI3 = 2, SPI4 = 3, } ... } }
So I've made it a point to use the Microsoft.SPOT.Hardware version, but I want to make sure that's safe.
#7362 NETMF constants
Posted by Blake Ramsdell on 09 January 2011 - 09:15 PM in General Discussion
IMHO there are two possibilities:
1) #if preprocessor directive and set appropriate symbol in Project Properties "Conditional Compilator symbols", you'd probably need to create new build configuration for each platform (i.e. "Debug - Board_XXX", "Debug - Board_YYY")
#if Board_XXX Cpu.Pin pin = (Cpu.Pin)xx; #elif Board_YYY Cpu.Pin pin = (Cpu.Pin)yy; #else #error Unsupported board. #endif
This path is a little futzy and problematic. For example:
#if BOARD_NETDUINO Cpu.Pin pin = SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D3; #elif BOARD_FEZ Cpu.Pin pin = (Cpu.Pin) GHIElectronics.NETMF.FEZ.FEZ_Pin.Digital.Di3; #else #error Unsupported board, smooth move. Why don't you figure all the possible #defines and stop wasting my time? #endif
As well as custom build code so that you include the right assemblies for the right variant of NETMF in the csproj file:
For Netduino:
<Reference Include="SecretLabs.NETMF.Hardware" /> <Reference Include="SecretLabs.NETMF.Hardware.Netduino" />
For FEZ:
<Reference Include="FEZDomino_GHIElectronics.NETMF.FEZ" />
And I presume there's a way to stick those in a PropertyGroup with an appropriate Condition on it.
2) Check SystemInfo.SystemID properties in runtime - if they are not filled correctly, you'd probably need to examine SystemInfo.OEMString
if(SystemInfo.SystemID.OEM == ... && SystemInfo.SystemID.Model == ...) { return (Cpu.Pin)xx; } if(SystemInfo.OEMString.IndexOf("Board_YYY") == 0) // For demonstration purposes only { return (Cpu.Pin)yy; }
This is what I actually did in the code. So I have one function that does the magic based on SystemInfo.OEMString:
// SetupCurrentShieldConfiguration is a little fragile -- it uses // Microsoft.SPOT.Hardware.SystemInfo.OEMString to try and figure out // which configuration to use. If that string isn't handled, you will // not survive. private static void SetupCurrentShieldConfiguration() { var oemString = SystemInfo.OEMString; switch (oemString) { case "GHI Electronics, LLC": CurrentShieldConfiguration = FezShieldConfiguration; break; case "Netduino by Secret Labs LLC": CurrentShieldConfiguration = NetduinoShieldConfiguration; break; default: break; } }
And then I cribbed the constants from the various places:
private class ShieldConfiguration { public Cpu.Pin RedLedPin { get; set; } public Cpu.Pin GreenLedPin { get; set; } public Cpu.Pin SpiChipSelectPin { get; set; } public Cpu.Pin OnboardLedPin { get; set; } } private static class NetduinoConstants { public const Cpu.Pin GPIO_PIN_D0 = (Cpu.Pin) 27; public const Cpu.Pin GPIO_PIN_D1 = (Cpu.Pin) 28; public const Cpu.Pin GPIO_PIN_D2 = (Cpu.Pin) 0; public const Cpu.Pin GPIO_PIN_D3 = (Cpu.Pin) 1; public const Cpu.Pin GPIO_PIN_D4 = (Cpu.Pin) 12; public const Cpu.Pin ONBOARD_LED = (Cpu.Pin) 55; } private static ShieldConfiguration NetduinoShieldConfiguration = new ShieldConfiguration { RedLedPin = NetduinoConstants.GPIO_PIN_D3, GreenLedPin = NetduinoConstants.GPIO_PIN_D4, SpiChipSelectPin = NetduinoConstants.GPIO_PIN_D2, OnboardLedPin = NetduinoConstants.ONBOARD_LED }; private static class FezConstants { public const Cpu.Pin LED = (Cpu.Pin) 4; public const Cpu.Pin Di4 = (Cpu.Pin) 19; public const Cpu.Pin Di3 = (Cpu.Pin) 31; public const Cpu.Pin Di2 = (Cpu.Pin) 33; } private static ShieldConfiguration FezShieldConfiguration = new ShieldConfiguration { RedLedPin = FezConstants.Di3, GreenLedPin = FezConstants.Di4, SpiChipSelectPin = FezConstants.Di2, OnboardLedPin = FezConstants.LED };
I kinda feel icky about cribbing the numbers for everyone's pins, but this was the most elegant way I could come up with a solution.
Thanks for all of the help -- further suggestions welcome.
#7373 NETMF constants
Posted by Blake Ramsdell on 09 January 2011 - 10:49 PM in General Discussion
In part this makes sure the user is aware of how many SPI modules are available. Also vendors can assign SPI1 to another constant other than zero. Microsoft recommends building a HardwareProvider for each board this way in the porting kit...
Now I'm really confused. So they provide a constant. That might not work at all on some particular platform. How is that useful?
It sounds like you should never, ever used the Microsoft-provided one, and always use the vendor-provided one, since it's possible that the vendor might choose a different SPI identifier than Microsoft...
#8349 What is "variable-bit SPI"?
Posted by Blake Ramsdell on 24 January 2011 - 11:37 PM in Netduino Plus 2 (and Netduino Plus 1)
Based on my somewhat moron non-hardware-guy understanding of SPI from Wikipedia, it's basically just a continuous bitstream -- you drive SS low, you start SCLK, and then data is latched on MISO and MOSI, one bit each direction per tick of SCLK.
Now, the current NETMF abstraction for SPI provides several functions. In my case, I'm transmitting a byte, and then I want to receive a byte in return from my SPI slave device. So I do:
var statusBuffer = new byte[2]; statusBuffer[0] = 0xD7; spi.WriteRead(statusBuffer, statusBuffer);
In the failure case, we are seeing MISO stuck at 0xFF. That is, statusBuffer[1] always equals 0xFF. It's supposed to be something different (specifically 0x8C).
So maybe if I understand more about "variable-bit SPI" it will help me diagnose this. I note from the provided ExtendedSpiConfiguration that the default value for BitsPerTransfer is 16. I am currently using a a regular SPI.Configuration, so I presume that I'm using 16 as BitsPerTransfer (the default).
So is a "transfer" defined as "the time between driving SS low and driving SS high"? If it is, then I may have some serious problems, because my transfers vary in length. I send various commands to the SPI slave device, and some commands are basically just the command byte, with a one byte response. Some commands have more structure (a command byte, three address bytes, 264 bytes of data), etc. So some transactions are one byte + one byte response, some transactions are 268 bytes + no response.
FYI, the device I'm talking to is a Xilinx XC3S50AN and the SPI documentation is here. The 0xD7 command is "Status Register Read". But I'm not sure understanding this is really needed.
My SPI code works fine on a Netduino Plus with older firmware and the 48KB RAM setup:
SolutionReleaseInfo.solutionVendorInfo: Netduino Plus (v4.1.0.5 b2) by Secret Labs LLC
#8387 What is "variable-bit SPI"?
Posted by Blake Ramsdell on 25 January 2011 - 09:49 AM in Netduino Plus 2 (and Netduino Plus 1)
#8412 What is "variable-bit SPI"?
Posted by Blake Ramsdell on 25 January 2011 - 08:38 PM in Netduino Plus 2 (and Netduino Plus 1)
The same thing happens with SPI. Most devices use 8-bit transfer (or 16-bit), but there are some that need 9-bit transfers. Or 11-bit. This seems to happen most frequently in SPI-based graphical displays.
OK, thanks Chris -- I have Xilinx SPI myopia and that's all 8-bit. Thanks for all the followup.
#21914 Reading binary resources piecemeal
Posted by Blake Ramsdell on 20 December 2011 - 05:21 PM in General Discussion
http://netmf.codeplex.com/
client_v4_2/CLR/Libraries/CorLib/corlib_native_System_Resources_ResourceManager.cpp
if(offset + length >= size) { length -= size - offset; }
Seems like this is wrong in at least a couple of ways. I think:
if((offset + length) > size) { length = (size - offset); }Is both clearer and less buggy.
So I think in your first case you ended up with:
if(0 + 8 >= 8) { length -= 8 - 0; }So your length ended up as 0 in this case.
if(0 + 20 >= 8) { length -= 8 - 0; }So your length ended up as 12 in this case (8 bytes of your resource data and four bytes of god knows what).
Happy to submit a patch, but I need to spend an hour and figure out how to do it and get the code. I was able to figure this out by browsing the source on CodePlex.
I'd say in the interim just make your resource one byte larger than you need. So nine bytes and then just know that the first eight are the "real" resource.
- Netduino Forums
- → Blake Ramsdell's Content
- Privacy Policy