chipKIT® Development Platform

Inspired by Arduino™

pinMode and OUTPUT not defined in library

Created Mon, 13 Jun 2011 01:56:34 +0000 by Jacob Christ


Jacob Christ

Mon, 13 Jun 2011 01:56:34 +0000

I'm working on porting an AVR lib to PIC32 and the following code will not complie in a library header file:

    pinMode(13, OUTPUT);

I have the code in a libraries directory in the sketch directory.

The output from the compiler is something like this:

In file included from board_test.cpp:5:0:
C:\Users\jacob\Documents\Arduino\libraries\USB_Host_Shield/Max3421e.h: In static member function 'static void MAX3421E::spi_init()':
C:\Users\jacob\Documents\Arduino\libraries\USB_Host_Shield/Max3421e.h:40:21: error: 'OUTPUT' was not declared in this scope
C:\Users\jacob\Documents\Arduino\libraries\USB_Host_Shield/Max3421e.h:40:27: error: 'pinMode' was not declared in this scope

I'm using mpide version Arduino 0022-chipkit-win-20110530

Jacob


My two axioms of embedded development First Axiom: If the tools work, then your job is easy. Second Axiom: The tools never work.


Jacob Christ

Mon, 13 Jun 2011 02:57:34 +0000

Related previously mentioned problem I think I'm seeing the following behavior.

The types byte, boolean and uint8_t are recognized in the .pde file but not in libraries. And indeed I get errors telling me the types are missing when I try to use them in a library.

I did a little searching and it seems that if your making a Arduino library that you need to include <WProgram.h> in your headers to pick up the Arduino constants and type definitions. So I did this, but now I'm getting i2c errors eventhough I'm not using i2c. I seem to recall that i2c library is not complete, but this is preventing further progress.

I have little Arduino experience but lots of PIC experience so I'm not sure if assertion is correct.

Jacob

My two axioms of embedded development First Axiom: If the tools work, then your job is easy. Second Axiom: The tools never work.


ricklon

Tue, 14 Jun 2011 03:15:29 +0000

Do you have a sample sketch that isolates this piece of code? If I do a standard basic sketch, put that one line in it does it fail the same way?


Jacob Christ

Tue, 14 Jun 2011 23:19:23 +0000

I built a simple sketch to try to isolate the problem and it does not occur. I'll have to build up the Arduino lib piece by piece to find out what is causing this.

Jacob

My two axioms of embedded development First Axiom: If the tools work, then your job is easy. Second Axiom: The tools never work.


Jacob Christ

Wed, 15 Jun 2011 00:19:24 +0000

I think I'm better understanding whats going on, though I don't understand it...

I've isolate issues (so far) to these two lines of code in a user contributed lib.

#define ON  true
#define OFF false

I suspect what it happening is that ON and OFF are being redefined in this lib, but I would be hard pressed to pull this from the errors generated as seen below:

In file included from c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/p32xxxx.h:11:0,
                 from c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/peripheral/adc10.h:44,
                 from c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/plib.h:45,
                 from C:\Users\jacob\Downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\cores\pic32/HardwareSerial.h:36,
                 from C:\Users\jacob\Downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\cores\pic32/WProgram.h:22,
                 from board_test.cpp:13:
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:27:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:58:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:179:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:219:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:258:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:298:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:337:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:379:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:413:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:447:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:481:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:515:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:545:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:580:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:615:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:650:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:685:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:726:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:809:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:888:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:942:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:1000:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:1080:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:1160:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:1314:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:1511:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:1538:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:1567:14: error: expected unqualified-id before numeric constant
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/proc/p32mx320f128h.h:2782:14: error: expected unqualified-id before numeric constant
In file included from c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/peripheral/spi_3xx_4xx.h:722:0,
                 from c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/peripheral/spi.h:44,
                 from c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/plib.h:61,
                 from C:\Users\jacob\Downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\cores\pic32/HardwareSerial.h:36,
                 from C:\Users\jacob\Downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\cores\pic32/WProgram.h:22,
                 from board_test.cpp:13:
c:\users\jacob\downloads\mpide-0022-chipkit-win-20110530\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/peripheral/legacy/spi_legacy.h:688:12: error: expected unqualified-id before numeric constant

Jacob

My two axioms of embedded development First Axiom: If the tools work, then your job is easy. Second Axiom: The tools never work.


jasonk

Wed, 15 Jun 2011 06:25:48 +0000

Yes, those two macros are probably causing the problem. There are SFR bits named ON and those macros will replace the names in the bitfields, causing strange errors... #define macros can be really dangerous.