chipKIT® Development Platform

Inspired by Arduino™

Using DSPI functions in 3rd party library

Created Thu, 14 Nov 2013 23:01:30 +0000 by biomurph


biomurph

Thu, 14 Nov 2013 23:01:30 +0000

Hi,

I'm trying to port some code to chipKIT and running into a problem when I compile. In the ChipKIT IDE, above the setup(), I have included the DSPI, instantiated it, and then included the library I'm building, and instantiated that.

#include <DSPI.h>
DSPI0  ADS;  // DSPI0 is connected to 13,12,11 on UNO32 board
#include <ADS1299Managerck.h>
ADS1299Managerck ADSManager;

then in the setup, I initialize them in order

ADS.begin(10);      
ADS.setMode(DSPI_MODE1);

 ADSManager.initialize(_version);

The problem I'm having is that the compiler throws an error saying 'ADS not declared' and I'm using the SPI inside my Library. I tried to include the DSPI in my library, but then got an error saying that DSPI.h was not found.....

Is there a trick to using DSPI inside my 3rd party library?


majenko

Fri, 15 Nov 2013 15:19:39 +0000

Yes, you have to pass the DSPI object into your library - it doesn't know about it until you do.

DSPI0 mySpi;

OtherClass thing(&mySpi);

And OtherClass has a constructor and stuff like:

#include <DSPI.h>

class OtherClass {
  DSPI *spi;

  public:
    OtherClass(DSPI *s) : spi(s) {}
};

Then in OtherClass you reference the *spi variable:

spi->begin();
//
spi->transfer(blah);

etc.