external DigitalInOut ?

17 Aug 2011

Is there an easy way to define IO pins to be used in multiple source blocks ? I keep on getting the 'multiply defined' pins. Declaring the pins 'external' does not seem to work.

17 Aug 2011

Do you mean create an object and them call that object from multiple files in the program? (basically make a global object). If so then yes you can. It is probably best shown in a program.

Import programGlobalTest

Shows how to use an object from multiple .cpp files

17 Aug 2011

I will try that tonight.

17 Aug 2011

Well with DigitalInOut it seems to work but not with SPI

extern SPI spi(p11, p12, p13); // mosi, miso, sclk

results in "SPI is ambiguous" and expected a ")"

here are my two global files:

global.c

#include "mbed.h"

// IEC hardware connections
DigitalInOut nSRQ(p18);     // DIN6 pin 1
DigitalInOut nATN(p17);     // DIN6 pin 3
DigitalInOut nCLK(p16);     // DIN6 pin 4
DigitalInOut nDATA(p15);    // DIN6 pin 5
DigitalInOut nRESET(p19);   // DIN6 pin 6
           
DigitalIn JUMPER_J2(p21);
DigitalIn JUMPER_J3(p22);

DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
DigitalOut myled3(LED3);
DigitalOut myled4(LED4);
                             
SPI spi(p11, p12, p13); // mosi, miso, sclk
DigitalOut SDCARD_CS(p14);
Timer timeout;
Serial linktopc(USBTX,USBRX);

and

global.h

#include "mbed.h"

// IEC hardware connections
extern DigitalInOut nSRQ(p18);     // DIN6 pin 1
extern DigitalInOut nATN(p17);     // DIN6 pin 3
extern DigitalInOut nCLK(p16);     // DIN6 pin 4
extern DigitalInOut nDATA(p15);    // DIN6 pin 5
extern DigitalInOut nRESET(p19);   // DIN6 pin 6
           
extern DigitalIn JUMPER_J2(p21);
extern DigitalIn JUMPER_J3(p22);

extern DigitalOut myled1(LED1);
extern DigitalOut myled2(LED2);
extern DigitalOut myled3(LED3);
extern DigitalOut myled4(LED4);
                             
extern SPI spi(p11, p12, p13); // mosi, miso, sclk
extern DigitalOut SDCARD_CS(p14);

// timer
extern Timer timeout;
extern Serial linktopc(USBTX,USBRX);
17 Aug 2011

Try to use only.

externe SPI spi;

does not declare again the associated pin.

18 Aug 2011

extern SPI spi; // mosi, miso, sclk

makes no difference:

Quote:

""SPI" is ambiguous" in file "global.h/<a href="#" onClick="window.open('/cookbook/Compiler-Error-266');">266</a>"

18 Aug 2011

kevin o3k wrote:

Try to use only.

externe SPI spi;

does not declare again the associated pin.

Yeah Kevin is right, don't use the pin numbers for any objects in the .h file. You will also want to reference the global.h file in the global.cpp file instead of the mbed.h, i.e. replace

#include "mbed.h"

with

#include "global.h"

Finally if that doesn't work try changing global.c to a C++ file instead of a C file (not sure if C handles this?)

18 Aug 2011

if you wanted to use the SPI on a separate code source block, why not just "extern" or reference the SPI write/read function(you have on main) on that code

19 Aug 2011

Herson Bagay wrote:

if you wanted to use the SPI on a separate code source block, why not just "extern" or reference the SPI write/read function(you have on main) on that code

Yes I think that is what I will do, abstract the IO to a seperate set of functions.

I am trying to port an existing program to the mbed and that program uses the IO pins in different source blocks so by defining them global I had hoped they would compile without too much changing.

22 Aug 2011

I replaced some defines by functions in main.c and declared them external in the troublesome source blocks and that worked like a charm. Just had to hunt for the pin names and add ()