compiling for Teensy fails but for Arduino is ok

Status
Not open for further replies.

NikoTeen

Well-known member
hi,
I am a beginner with Teensy. Up to now I was using Arduino with the Arduino IDE.
Now I want to run some code written for Arduino Uno with Teensy 3.2.
Everything is ok with Arduino but compilation for Teensy fails.
The Teensy extensions for Arduino IDE are installed.

For the code:
Code:
bool nextPulse (word width) {
        if (state != DONE)

            anz_p++;
            switch (decode(width)) {
                case -1: resetDecoder();  break;
                case 1:  done(); break;
            }
        return isDone();
    }
the compiler reports the error:
Code:
In file included from H:\Arduino\examples\GSM-Tests\WindEmpfSend\WindEmpfSend.ino:30:0:

C:\Users\...\Temp\arduino_build_756235\sketch\OregonDecodeV3_2.h: In member function 'bool OOK_OregonDecodeV3_2::nextPulse(word)':

C:\Users\...\Temp\arduino_build_756235\sketch\OregonDecodeV3_2.h:87:17: warning: case label value is less than minimum value for type

                 case -1: resetDecoder();  break;

                 ^
In Arduino sketches char is a signed byte, not in Teensy?

NikoTeen
 
Looks like 'word' is an unsigned 16-bit integer so the compiler is warning that -1 is not valid.

Pete
 
Char is signed on AVR. Per ARM ABI, it's unsigned (not just Teensy 3.x, other ARM-based Arduino platforms as well).

Thank you for the explanation.

Testing my Arduino sketch on Teensy 3.2 rises new questions.
1) where can i get a list of data types valid for ARM controllers?
2) the sketch contains defines, e.g. "#ifdef __AVR_ATmega2560__". Are there similar defines for Teensy and where can i find them?
3) in the tools menue of the Arduino IDE, selecting Teensy 3.2 provides a choice about the CPU speed. It defaults to 96 MHz (overclocked). I guess my Teensy 3.2 board works with 72 MHz, but i am not sure. How can i find out what CPU speed is the right one for my board?
 
A set of data types: Not sure where to tell you to look for this. There are places like <stdint.h>
If you have specific needs for size and sign, it is better to use variable types like:
uint8_t - unsigned int 8 bits
int8_t - signed int 8 bits
uint16_t ...



There are several defines that can work :
For all Arm Teensy boards: #if defined(__arm__) && defined(TEENSYDUINO)

For all of the Teensy 3.x: #if defined(KINETISK)

For Teensy 3.0 only: #if defined(__MK20DX128__)
For Teensy 3.1-2: #if defined(__MK20DX256__)
For Teensy 3.5: #if defined(__MK64FX512__)
For Teensy 3.6: #if defined(__MK66FX1M0__)

For Teensy LC there is:
#ifdef KINETISL
or there is: #if defined(__MKL26Z64__)

3) I typically run a 3.2 at 120mhz. 72 is fine, you can run much slower if you want to as well.
 
Status
Not open for further replies.
Back
Top