Hello,
I have a Teensy 3.2 hooked up to a Adafruit Data Logging Shield (I'm migrating an existing project from Arduino Mega to Teensy)
Teensy is powered via USB.
Wiring:
Apart from the obvious +5V (splitted from USB +5V power) and +3.3V (wired to "3.3V 250mA Max"), I have:
IORef on 3.3V
ChipSelect on Pin10
MOSI on Pin11
MISO on Pin12
Clock on Pin13
I have Arduino IDE 1.6.5r5 and Teensyduino 1.2.6b1; host OS is Windows7-64.
On Arduino Mega, I used to load the Adafruit SD library (SD.h).
My initialization call was:
and I used to access files like that:
and all was fine and dandy.
Now, the project won't even compile:
I thought "Too bad, Adafruit's SD library is not compatibile with Teensyduino ", so I tried to switch to "SdFat" library:
and changed the initialization code to:
but now, while SD.begin apparently works (result != 0), I can't open files (SD.open always fails).
I wonder, if I need to use some other library?
*** Update: I tried the "standard" SD.h too, same result: SD.begin ok but SD.open fails on any file on the SD. Tried different SD cards as well
Is there an example of working SD code for Teensyduino 1.2.6 and Arduino IDE 1.6.5?
Or maybe I did the wiring wrong? I think using pin 10 to 13 should be OK actually...
Thanks for any help.
Honestly I was hoping to switch to Teensy more easily; it's my fault for sure, but maybe a Arduino->Teensy sketch migration guide for beginners could be useful...?
Fernando
I have a Teensy 3.2 hooked up to a Adafruit Data Logging Shield (I'm migrating an existing project from Arduino Mega to Teensy)
Teensy is powered via USB.
Wiring:
Apart from the obvious +5V (splitted from USB +5V power) and +3.3V (wired to "3.3V 250mA Max"), I have:
IORef on 3.3V
ChipSelect on Pin10
MOSI on Pin11
MISO on Pin12
Clock on Pin13
I have Arduino IDE 1.6.5r5 and Teensyduino 1.2.6b1; host OS is Windows7-64.
On Arduino Mega, I used to load the Adafruit SD library (SD.h).
My initialization call was:
Code:
SD.begin(10, 11, 12, 13)
and I used to access files like that:
Code:
File myFile = SD.open("myfile.dat", FILE_READ);
and all was fine and dandy.
Now, the project won't even compile:
Code:
Sd2Card.cpp:30:17: error: 'RwReg' does not name a type
:static volatile RwReg *mosiport, *clkport, *misoport
Sd2Card.cpp:In function 'void spiSend(uint8_t)
Sd2Card.cpp:60:10: error: 'clkport' was not declared in this scope
:*clkport &= ~clkpinmask
Sd2Card.cpp:62:12: error: 'mosiport' was not declared in this scope
:*mosiport |= mosipinmask
Sd2Card.cpp:64:12: error: 'mosiport' was not declared in this scope
:*mosiport &= ~mosipinmask
Sd2Card.cpp:69:8: error: 'clkport' was not declared in this scope
:*clkport &= ~clkpinmask
Sd2Card.cpp:In function 'uint8_t spiRec()
Sd2Card.cpp:88:6: error: 'mosiport' was not declared in this scope
:*mosiport |= mosipinmask
Sd2Card.cpp:91:8: error: 'clkport' was not declared in this scope
:*clkport |= clkpinmask
Sd2Card.cpp:95:13: error: 'misoport' was not declared in this scope
:if ((*misoport) & misopinmask) data |= 1
Sd2Card.cpp:In member function 'uint8_t Sd2Card::init(uint8_t, uint8_t, int8_t, int8_t, int8_t)
Sd2Card.cpp:302:5: error: 'clkport' was not declared in this scope
:clkport = portOutputRegister(digitalPinToPort(clockPin_))
Sd2Card.cpp:304:5: error: 'mosiport' was not declared in this scope
:mosiport = portOutputRegister(digitalPinToPort(mosiPin_))
Sd2Card.cpp:306:5: error: 'misoport' was not declared in this scope
:misoport = portInputRegister(digitalPinToPort(misoPin_))
I thought "Too bad, Adafruit's SD library is not compatibile with Teensyduino ", so I tried to switch to "SdFat" library:
Code:
#include <SdFat.h>
SdFat SD;
and changed the initialization code to:
Code:
SD.begin(SD_CHIPSELECT)
but now, while SD.begin apparently works (result != 0), I can't open files (SD.open always fails).
I wonder, if I need to use some other library?
*** Update: I tried the "standard" SD.h too, same result: SD.begin ok but SD.open fails on any file on the SD. Tried different SD cards as well
Is there an example of working SD code for Teensyduino 1.2.6 and Arduino IDE 1.6.5?
Or maybe I did the wiring wrong? I think using pin 10 to 13 should be OK actually...
Thanks for any help.
Honestly I was hoping to switch to Teensy more easily; it's my fault for sure, but maybe a Arduino->Teensy sketch migration guide for beginners could be useful...?
Fernando
Last edited: