Netduino home hardware projects downloads community

Jump to content


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

Using SPI Directly on Netduino Go

Netduino Go

Best Answer johncc, 14 March 2013 - 10:35 PM

Thanks Guys!  That works like a charm.  In case it is useful to others, here is the code I used to directly access the Netduino Go SPI port (i.e. not using a GoBus module):

 

 

GoSocket socket = SecretLabs.NETMF.Hardware.NetduinoGo.GoSockets.Socket5;

Cpu.Pin socketGpioPin;

SPI.SPI_module socketSpiModule;

Cpu.Pin socketSpiSlaveSelectPin;

 

socket.GetPhysicalResources(out socketGpioPin, out socketSpiModule, out socketSpiSlaveSelectPin);

SPI.Configuration spiConfiguration = new SPI.Configuration(

Cpu.Pin.GPIO_NONE, //Chip Select pin

false, // Chip Select Active State low

0, // Chip Select Setup Time 0us

0, // Chip Select Hold Time 0us

false, // Clock Idle State

true, // Clock Edge

5000, // Clock Rate in kHz

socketSpiModule); //SPI Module

SPI spi = new SPI(spiConfiguration);

Thanks again for all the great help!

John

Go to the full post


  • Please log in to reply
8 replies to this topic

#1 johncc

johncc

    New Member

  • Members
  • Pip
  • 6 posts

Posted 11 March 2013 - 10:14 PM

I have a Netduino Go and Shieldbase used to communicate with my own SPI peripherals.  I find this is too slow so I want to be able to use the Netduino Go SPI directly (by manally wiring to a GoBus connector).  I know this is not the recommended or even desirable way to use the Netduino Go, but is it possible?  When I try to create the SPI port:

 

 

 

SPI.Configuration spiConfiguration = new SPI.Configuration(

Pins.GPIO_NONE, //Chip Select pin

false, // Chip Select Active State low

0, // Chip Select Setup Time 0us

0, // Chip Select Hold Time 0us

false, // Clock Idle State

true, // Clock Edge

1000, // Clock Rate in kHz

SPI_Devices.SPI1); //SPI Module

SPI spi = new SPI(spiConfiguration);

 

I get an exception in NetduinoGo.Shieldbase.dll.

 

Many thanks for any suggestions!



#2 bsilvereagle

bsilvereagle

    Member

  • Members
  • PipPip
  • 11 posts

Posted 13 March 2013 - 10:08 PM

I'm not sure why you are getting an exception in the Shieldbase dll, but you need to specify a pin for the Chip Select. 

 

http://www.netduino....o/schematic.pdf

 

If you're using a device connected to GoSocket 3 you would use (Cpu.Pin)4 as can be seen in the above schematic. 

 

Also, I and others have run into SPI bugs when running under ~3000 kHz. So you may want to up your speed. 



#3 Arron Chapman

Arron Chapman

    Advanced Member

  • Members
  • PipPipPip
  • 289 posts
  • LocationOregon, USA

Posted 14 March 2013 - 12:45 AM

I have a Netduino Go and Shieldbase used to communicate with my own SPI peripherals.  I find this is too slow so I want to be able to use the Netduino Go SPI directly (by manally wiring to a GoBus connector).  I know this is not the recommended or even desirable way to use the Netduino Go, but is it possible?  When I try to create the SPI port:

 

 

 

SPI.Configuration spiConfiguration = new SPI.Configuration(

Pins.GPIO_NONE, //Chip Select pin

false, // Chip Select Active State low

0, // Chip Select Setup Time 0us

0, // Chip Select Hold Time 0us

false, // Clock Idle State

true, // Clock Edge

1000, // Clock Rate in kHz

SPI_Devices.SPI1); //SPI Module

SPI spi = new SPI(spiConfiguration);

 

I get an exception in NetduinoGo.Shieldbase.dll.

 

Many thanks for any suggestions!

 

You need to remove all of the GoBus references, at startup they reserve the pins on the uC.

 

 

 

I'm not sure why you are getting an exception in the Shieldbase dll, but you need to specify a pin for the Chip Select. 

 

Also, I and others have run into SPI bugs when running under ~3000 kHz. So you may want to up your speed.

A CS pin isn't expressly needed.

 

I havn't seen any issues using SPI under 3Mhz, could you share some links?


When you talk EE use small words, I'm just a Software Developer :)
My Blog/Site and Everything Else

If my post helped you please consider pressing the "Like This" button in the bottom right-hand corner.

 

Oh my. So many things, so little money!!

 


#4 johncc

johncc

    New Member

  • Members
  • Pip
  • 6 posts

Posted 14 March 2013 - 01:20 AM

> You need to remove all of the GoBus references, at startup they reserve the pins on the uC.

 

Thanks for the help!  Can you elaborate on exactly what you mean (sorry I am new at netduino)?  I assume you mean remove any GoBus references under References in the Solution Explorer? I tried that and still get the same Exception.  The only references I have are Microsoft.SPOT.Hardware, mscorlib, and SecretLabs.NETMF.Hardware.NetduinoPlus. 

 

It makes sense to me that I am getting some kind of collision with the GoBus code.  I just don't know how to get rid of all GoBus code...  From the call stack (below) it looks like it is trying to use the shieldbase even though I want to use the SPI port on the NetduinoGo directly...

 

In case it helps, here is the call stack at the exception.  It occurs in the main program when I try to create the SPI port:

 

GoBusSerialTransport.dll!GoBus.GoBusSerialTransport.ResetSlave() Line 1050 + 0x47 bytes C# GoBusSerialTransport.dll!GoBus.GoBusSerialTransport.GoBusSerialTransport(string portName) Line 178 + 0x2f bytes C# NetduinoGo.ShieldBase.dll!NetduinoGo.ShieldBase.ShieldBase() Line 146 + 0xfa bytes C# [External Code]  GoBus.dll!GoBus.GoBusManager.GetShieldBase() Line 36 + 0x23 bytes C# [External Code]  > NetduinoGoApplication1.exe!NetduinoGoApplication1.Program.Main() Line 218 + 0x1a bytes C#  

Thanks again!



#5 neslekkim

neslekkim

    Advanced Member

  • Members
  • PipPipPip
  • 350 posts
  • LocationOslo, Norway

Posted 14 March 2013 - 07:13 AM

What is line 218 in your code?

--
Asbjrn


#6 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 14 March 2013 - 02:21 PM

Hi johncc, With Netduino Go, the first SPI bus is mapped to the Shield Base. This is designed to provide a consistent and code-compatible experience between Netduino and Netduino Go. If you want to access the SPI bus directly with Netduino Go you can, but you'll want to remove all GoBus-related assemblies from your project references and then reference the root SPI channel directly. For an example of that, grab the C# driver source for the RGB LED module. BTW--there's nothing wrong with hacking into your Netduino Go and using SPI directly. Netduino Go is designed for GoBus Virtual I/O...but half the fun of playing with Netduino can be hacking it :) Chris

#7 neslekkim

neslekkim

    Advanced Member

  • Members
  • PipPipPip
  • 350 posts
  • LocationOslo, Norway

Posted 14 March 2013 - 02:25 PM

Regarding sources (since you mentions it again), and hacking, how is the progress of getting everything in an repository ? When one sees the effort community puts into it (regarding the stdfu replacement), an open repository should be of good benefit for all, but still one need to hunt around to find parts of the sources.

--
Asbjrn


#8 Arron Chapman

Arron Chapman

    Advanced Member

  • Members
  • PipPipPip
  • 289 posts
  • LocationOregon, USA

Posted 14 March 2013 - 04:50 PM

> You need to remove all of the GoBus references, at startup they reserve the pins on the uC.

 

Thanks for the help!  Can you elaborate on exactly what you mean (sorry I am new at netduino)?  I assume you mean remove any GoBus references under References in the Solution Explorer? I tried that and still get the same Exception.  The only references I have are Microsoft.SPOT.Hardware, mscorlib, and SecretLabs.NETMF.Hardware.NetduinoPlus. 

 

Yes that is correct, you want to remove the references.  Don't use the NetduinoPlus references, it's pins are not compatible with the Go.


When you talk EE use small words, I'm just a Software Developer :)
My Blog/Site and Everything Else

If my post helped you please consider pressing the "Like This" button in the bottom right-hand corner.

 

Oh my. So many things, so little money!!

 


#9 johncc

johncc

    New Member

  • Members
  • Pip
  • 6 posts

Posted 14 March 2013 - 10:35 PM   Best Answer

Thanks Guys!  That works like a charm.  In case it is useful to others, here is the code I used to directly access the Netduino Go SPI port (i.e. not using a GoBus module):

 

 

GoSocket socket = SecretLabs.NETMF.Hardware.NetduinoGo.GoSockets.Socket5;

Cpu.Pin socketGpioPin;

SPI.SPI_module socketSpiModule;

Cpu.Pin socketSpiSlaveSelectPin;

 

socket.GetPhysicalResources(out socketGpioPin, out socketSpiModule, out socketSpiSlaveSelectPin);

SPI.Configuration spiConfiguration = new SPI.Configuration(

Cpu.Pin.GPIO_NONE, //Chip Select pin

false, // Chip Select Active State low

0, // Chip Select Setup Time 0us

0, // Chip Select Hold Time 0us

false, // Clock Idle State

true, // Clock Edge

5000, // Clock Rate in kHz

socketSpiModule); //SPI Module

SPI spi = new SPI(spiConfiguration);

Thanks again for all the great help!

John







Also tagged with one or more of these keywords: Netduino Go

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

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.