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

Multiple Identical Class-Driven SPI devices

spi

  • Please log in to reply
2 replies to this topic

#1 Verdris

Verdris

    Advanced Member

  • Members
  • PipPipPip
  • 128 posts
  • LocationReno, NV

Posted 14 May 2013 - 12:49 AM

Hi all, I have this:

namespace TwoADC{    public class Program    {        public static SPI.Configuration LPMConfig = new SPI.Configuration(Pins.GPIO_PIN_D10, false, 0, 0, false, false, 1000, SPI_Devices.SPI1);        public static SPI.Configuration ScatteringConfig = new SPI.Configuration(Pins.GPIO_PIN_D7, false, 0, 0, false, false, 1000, SPI_Devices.SPI1);        public static AD7714 LaserADC = new AD7714(LPMConfig, Pins.GPIO_PIN_D9, Pins.GPIO_PIN_D8);        public static AD7714 ScatteringADC = new AD7714(ScatteringConfig, Pins.GPIO_PIN_D6, Pins.GPIO_PIN_D5);

And the AD7714 class I'm trying to adjust:

namespace TwoADC{    public class AD7714    {        public AD7714(SPI.Configuration gooby, Cpu.Pin DataReadyPin, Cpu.Pin ResetPin)        {            ADC_drdy = new InputPort(DataReadyPin, false, Port.ResistorMode.PullUp);            ADC_reset = new OutputPort(ResetPin, true);            ADCBus = new SPI(gooby);        }        private static InputPort ADC_drdy { get; set; }        private static OutputPort ADC_reset { get; set; }        private static SPI ADCBus { get; set; }

What I would like to do is declare each ADC separately, so that I can then call

int Scattering = ScatteringADC.ReadChannel(1, 1, false, 40);int LPM = LaserADC.ReadChannel(1, 1, false, 40);

And have each call address a different SPI device. The SPI devices are identical.

 

What happens is when I try to initialize the second SPI object, the program throws a System.InvalidOperationException. I have no idea why, but I assume it's in trying to declare two different objects on the same bus. When I comment out either of the AD7714 objects, the code compiles and runs. I'm using different Chip Select pins each time in the constructors, so I don't know where the complaint is.

 

Help!



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 14 May 2013 - 12:56 AM

Hi Verdis,

 

We generally use one SPI class instance, with SPI Configs that we swap in and out as needed.

 

Have you seen the .NET Micro Framework toolbox, coordinated by our own Stefan Thoolen? 

 

It has a MultiSPI class which takes care of the swapping for you:

http://netmftoolbox....rdware.MultiSPI

 

Does that help get you pointed in the right direction?

 

Chris
 



#3 Verdris

Verdris

    Advanced Member

  • Members
  • PipPipPip
  • 128 posts
  • LocationReno, NV

Posted 17 May 2013 - 04:32 PM

Hi Verdis,

 

We generally use one SPI class instance, with SPI Configs that we swap in and out as needed.

 

Have you seen the .NET Micro Framework toolbox, coordinated by our own Stefan Thoolen? 

 

It has a MultiSPI class which takes care of the swapping for you:

http://netmftoolbox....rdware.MultiSPI

 

Does that help get you pointed in the right direction?

 

Chris
 

Chris,

 

Thanks for the reply. I looked through the code and it will indeed do what I want. I'll have to re-write my driver to include the MultiSPI support, and I'll post results when done.







Also tagged with one or more of these keywords: spi

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.