Arduino spi h error



SPI library compile errors when compiling for Arduino Due #2516

Comments

dinodev76 commented Dec 28, 2014

Can someone please tell me where to find the SPI library code that will work for an Arduino Due? I’m getting the following compile errors when using the library found at https://github.com/arduino/Arduino/tree/master/libraries/SPI:

Compiling ‘SDCardInfo’ for ‘Arduino Due (Programming Port)’
SDCardInfo.ino:In file included from
SPI.h:In member function ‘void SPISettings::init_AlwaysInline(uint32_t, uint8_t, uint8_t)’
SPI.h:146:16: error: ‘SPE’ was not declared in this scope
:0) |
:^
SPI.h:146:19: error: ‘_BV’ was not declared in this scope
:0) |
:^
SPI.h:146:27: error: ‘MSTR’ was not declared in this scope
:0) |
:^
SPI.h:146:65: error: ‘DORD’ was not declared in this scope
:0) |
:^
SPI.h:In static member function ‘static void SPIClass::beginTransaction(SPISettings)’
SPI.h:180:22: error: ‘SREG’ was not declared in this scope
:uint8_t sreg = SREG;
:^
SPI.h:203:5: error: ‘SPCR’ was not declared in this scope
:SPCR = settings.spcr;
:^
SPI.h:204:5: error: ‘SPSR’ was not declared in this scope
:SPSR = settings.spsr;
:^
SPI.h:In static member function ‘static uint8_t SPIClass::transfer(uint8_t)’
SPI.h:209:5: error: ‘SPDR’ was not declared in this scope
:SPDR = data;
:^
SPI.h:217:14: error: ‘SPSR’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ; \ wait
:^
SPI.h:217:25: error: ‘SPIF’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ; \ wait
:^
SPI.h:217:29: error: ‘_BV’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ; \ wait
:^
SPI.h:In static member function ‘static uint16_t SPIClass::transfer16(uint16_t)’
SPI.h:223:11: error: ‘SPCR’ was not declared in this scope
:if (!(SPCR & _BV(DORD))) <
:^
SPI.h:223:22: error: ‘DORD’ was not declared in this scope
:if (!(SPCR & _BV(DORD))) <
:^
SPI.h:223:26: error: ‘_BV’ was not declared in this scope
:if (!(SPCR & _BV(DORD))) <
:^
SPI.h:224:7: error: ‘SPDR’ was not declared in this scope
:SPDR = in.msb;
:^
SPI.h:226:16: error: ‘SPSR’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ;
:^
SPI.h:226:27: error: ‘SPIF’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ;
:^
SPI.h:230:16: error: ‘SPSR’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ;
:^
SPI.h:230:27: error: ‘SPIF’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ;
:^
SPI.h:233:7: error: ‘SPDR’ was not declared in this scope
:SPDR = in.lsb;
:^
SPI.h:235:16: error: ‘SPSR’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ;
:^
SPI.h:235:27: error: ‘SPIF’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ;
:^
SPI.h:239:16: error: ‘SPSR’ was not declared in this scope
:while (!(SPSR & BV(SPIF))) ;
:^
SPI.h:239:27: error: ‘SPIF’ was not declared in this scope
:while (!(SPSR & BV(SPIF))) ;
:^
SPI.h:In static member function ‘static void SPIClass::transfer(void
, size_t)’
SPI.h:247:5: error: ‘SPDR’ was not declared in this scope
:SPDR = p;
:^
SPI.h:250:16: error: ‘SPSR’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ;
:^
SPI.h:250:27: error: ‘SPIF’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ;
:^
SPI.h:250:31: error: ‘_BV’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ;
:^
SPI.h:255:14: error: ‘SPSR’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ;
:^
SPI.h:255:25: error: ‘SPIF’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ;
:^
SPI.h:255:29: error: ‘_BV’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ;
:^
SPI.h:In static member function ‘static void SPIClass::endTransaction()’
SPI.h:281:9: error: ‘SREG’ was not declared in this scope
:SREG = interruptSave;
:^
SPI.h:In static member function ‘static void SPIClass::setBitOrder(uint8_t)’
SPI.h:292:31: error: ‘SPCR’ was not declared in this scope
:if (bitOrder == LSBFIRST) SPCR |= _BV(DORD);
:^
SPI.h:292:43: error: ‘DORD’ was not declared in this scope
:if (bitOrder == LSBFIRST) SPCR |= _BV(DORD);
:^
SPI.h:292:47: error: ‘_BV’ was not declared in this scope
:if (bitOrder == LSBFIRST) SPCR |= _BV(DORD);
:^
SPI.h:293:10: error: ‘SPCR’ was not declared in this scope
:else SPCR &=

(_BV(DORD));
:^
SPI.h:293:24: error: ‘DORD’ was not declared in this scope
:else SPCR &=

(_BV(DORD));
:^
SPI.h:293:28: error: ‘_BV’ was not declared in this scope
:else SPCR &=

(_BV(DORD));
:^
SPI.h:In static member function ‘static void SPIClass::setDataMode(uint8_t)’
SPI.h:298:5: error: ‘SPCR’ was not declared in this scope
:SPCR = (SPCR &

SPI_MODE_MASK) | dataMode;
:^
SPI.h:In static member function ‘static void SPIClass::setClockDivider(uint8_t)’
SPI.h:303:5: error: ‘SPCR’ was not declared in this scope
:SPCR = (SPCR &

SPI_CLOCK_MASK) | (clockDiv & SPI_CLOCK_MASK);
:^
SPI.h:304:5: error: ‘SPSR’ was not declared in this scope
:SPSR = (SPSR &

SPI_2XCLOCK_MASK) | ((clockDiv >> 2) & SPI_2XCLOCK_MASK);
:^
SPI.h:In static member function ‘static void SPIClass::attachInterrupt()’
SPI.h:309:42: error: ‘SPCR’ was not declared in this scope
:inline static void attachInterrupt() < SPCR |= _BV(SPIE); >
:^
SPI.h:309:54: error: ‘SPIE’ was not declared in this scope
:inline static void attachInterrupt() < SPCR |= _BV(SPIE); >
:^
SPI.h:309:58: error: ‘_BV’ was not declared in this scope
:inline static void attachInterrupt() < SPCR |= _BV(SPIE); >
:^
SPI.h:In static member function ‘static void SPIClass::detachInterrupt()’
SPI.h:310:42: error: ‘SPCR’ was not declared in this scope
:inline static void detachInterrupt() < SPCR &=

_BV(SPIE); >
:^
SPI.h:310:55: error: ‘SPIE’ was not declared in this scope
:inline static void detachInterrupt() < SPCR &=

_BV(SPIE); >
:^
SPI.h:310:59: error: ‘_BV’ was not declared in this scope
:inline static void detachInterrupt() < SPCR &=

_BV(SPIE); >
:^
SPI.cpp:In file included from
SPI.h:In member function ‘void SPISettings::init_AlwaysInline(uint32_t, uint8_t, uint8_t)’
SPI.h:146:16: error: ‘SPE’ was not declared in this scope
:0) |
:^
SPI.h:146:19: error: ‘_BV’ was not declared in this scope
:0) |
:^
SPI.h:146:27: error: ‘MSTR’ was not declared in this scope
:0) |
:^
SPI.h:146:65: error: ‘DORD’ was not declared in this scope
:0) |
:^
SPI.h:In static member function ‘static void SPIClass::beginTransaction(SPISettings)’
SPI.h:180:22: error: ‘SREG’ was not declared in this scope
:uint8_t sreg = SREG;
:^
SPI.h:203:5: error: ‘SPCR’ was not declared in this scope
:SPCR = settings.spcr;
:^
SPI.h:204:5: error: ‘SPSR’ was not declared in this scope
:SPSR = settings.spsr;
:^
SPI.h:In static member function ‘static uint8_t SPIClass::transfer(uint8_t)’
SPI.h:209:5: error: ‘SPDR’ was not declared in this scope
:SPDR = data;
:^
SPI.h:217:14: error: ‘SPSR’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ; \ wait
:^
SPI.h:217:25: error: ‘SPIF’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ; \ wait
:^
SPI.h:217:29: error: ‘_BV’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ; \ wait
:^
SPI.h:In static member function ‘static uint16_t SPIClass::transfer16(uint16_t)’
SPI.h:223:11: error: ‘SPCR’ was not declared in this scope
:if (!(SPCR & _BV(DORD))) <
:^
SPI.h:223:22: error: ‘DORD’ was not declared in this scope
:if (!(SPCR & _BV(DORD))) <
:^
SPI.h:223:26: error: ‘_BV’ was not declared in this scope
:if (!(SPCR & _BV(DORD))) <
:^
SPI.h:224:7: error: ‘SPDR’ was not declared in this scope
:SPDR = in.msb;
:^
SPI.h:226:16: error: ‘SPSR’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ;
:^
SPI.h:226:27: error: ‘SPIF’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ;
:^
SPI.h:230:16: error: ‘SPSR’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ;
:^
SPI.h:230:27: error: ‘SPIF’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ;
:^
SPI.h:233:7: error: ‘SPDR’ was not declared in this scope
:SPDR = in.lsb;
:^
SPI.h:235:16: error: ‘SPSR’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ;
:^
SPI.h:235:27: error: ‘SPIF’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ;
:^
SPI.h:239:16: error: ‘SPSR’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ;
:^
SPI.h:239:27: error: ‘SPIF’ was not declared in this scope
:while (!(SPSR & BV(SPIF))) ;
:^
SPI.h:In static member function ‘static void SPIClass::transfer(void
, size_t)’
SPI.h:247:5: error: ‘SPDR’ was not declared in this scope
:SPDR = _p;
:^
SPI.h:250:16: error: ‘SPSR’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ;
:^
SPI.h:250:27: error: ‘SPIF’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ;
:^
SPI.h:250:31: error: ‘_BV’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ;
:^
SPI.h:255:14: error: ‘SPSR’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ;
:^
SPI.h:255:25: error: ‘SPIF’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ;
:^
SPI.h:255:29: error: ‘_BV’ was not declared in this scope
:while (!(SPSR & _BV(SPIF))) ;
:^
SPI.h:In static member function ‘static void SPIClass::endTransaction()’
SPI.h:281:9: error: ‘SREG’ was not declared in this scope
:SREG = interruptSave;
:^
SPI.h:In static member function ‘static void SPIClass::setBitOrder(uint8_t)’
SPI.h:292:31: error: ‘SPCR’ was not declared in this scope
:if (bitOrder == LSBFIRST) SPCR |= _BV(DORD);
:^
SPI.h:292:43: error: ‘DORD’ was not declared in this scope
:if (bitOrder == LSBFIRST) SPCR |= _BV(DORD);
:^
SPI.h:292:47: error: ‘_BV’ was not declared in this scope
:if (bitOrder == LSBFIRST) SPCR |= _BV(DORD);
:^
SPI.h:293:10: error: ‘SPCR’ was not declared in this scope
:else SPCR &=

(_BV(DORD));
:^
SPI.h:293:24: error: ‘DORD’ was not declared in this scope
:else SPCR &=

(_BV(DORD));
:^
SPI.h:293:28: error: ‘_BV’ was not declared in this scope
:else SPCR &=

(_BV(DORD));
:^
SPI.h:In static member function ‘static void SPIClass::setDataMode(uint8_t)’
SPI.h:298:5: error: ‘SPCR’ was not declared in this scope
:SPCR = (SPCR &

SPI_MODE_MASK) | dataMode;
:^
SPI.h:In static member function ‘static void SPIClass::setClockDivider(uint8_t)’
SPI.h:303:5: error: ‘SPCR’ was not declared in this scope
:SPCR = (SPCR &

SPI_CLOCK_MASK) | (clockDiv & SPI_CLOCK_MASK);
:^
SPI.h:304:5: error: ‘SPSR’ was not declared in this scope
:SPSR = (SPSR &

SPI_2XCLOCK_MASK) | ((clockDiv >> 2) & SPI_2XCLOCK_MASK);
:^
SPI.h:In static member function ‘static void SPIClass::attachInterrupt()’
SPI.h:309:42: error: ‘SPCR’ was not declared in this scope
:inline static void attachInterrupt() < SPCR |= _BV(SPIE); >
:^
SPI.h:309:54: error: ‘SPIE’ was not declared in this scope
:inline static void attachInterrupt() < SPCR |= _BV(SPIE); >
:^
SPI.h:309:58: error: ‘_BV’ was not declared in this scope
:inline static void attachInterrupt() < SPCR |= _BV(SPIE); >
:^
SPI.h:In static member function ‘static void SPIClass::detachInterrupt()’
SPI.h:310:42: error: ‘SPCR’ was not declared in this scope
:inline static void detachInterrupt() < SPCR &=

_BV(SPIE); >
:^
SPI.h:310:55: error: ‘SPIE’ was not declared in this scope
:inline static void detachInterrupt() < SPCR &=

_BV(SPIE); >
:^
SPI.h:310:59: error: ‘_BV’ was not declared in this scope
:inline static void detachInterrupt() < SPCR &=

_BV(SPIE); >
:^
SPI.cpp:In static member function ‘static void SPIClass::begin()’
SPI.cpp:28:18: error: ‘SREG’ was not declared in this scope
:uint8_t sreg = SREG;
:^
SPI.cpp:42:5: error: ‘SPCR’ was not declared in this scope
:SPCR |= _BV(MSTR);
:^
SPI.cpp:42:17: error: ‘MSTR’ was not declared in this scope
:SPCR |= _BV(MSTR);
:^
SPI.cpp:42:21: error: ‘_BV’ was not declared in this scope
:SPCR |= _BV(MSTR);
:^
SPI.cpp:43:17: error: ‘SPE’ was not declared in this scope
:SPCR |= _BV(SPE);
:^
SPI.cpp:In static member function ‘static void SPIClass::end()’
SPI.cpp:59:18: error: ‘SREG’ was not declared in this scope
:uint8_t sreg = SREG;
:^
SPI.cpp:66:5: error: ‘SPCR’ was not declared in this scope
:SPCR &=

_BV(SPE);
:^
SPI.cpp:66:18: error: ‘SPE’ was not declared in this scope
:SPCR &=

_BV(SPE);
:^
SPI.cpp:66:21: error: ‘_BV’ was not declared in this scope
:SPCR &=

BV(SPE);
:^
SPI.cpp:In static member function ‘static void SPIClass::usingInterrupt(uint8_t)’
SPI.cpp:115:18: error: ‘SREG’ was not declared in this scope
:uint8_t sreg = SREG;
:^
SPI.cpp:In static member function ‘static void SPIClass::notUsingInterrupt(uint8_t)’
SPI.cpp:158:18: error: ‘SREG’ was not declared in this scope
:uint8_t sreg = SREG;
:^
Sd2Card.cpp:In function ‘void spiSend(uint8_t)’
Sd2Card.cpp:33:3: error: ‘SPDR’ was not declared in this scope
:SPDR = b;
:^
Sd2Card.cpp:34:12: error: ‘SPSR’ was not declared in this scope
:while (!(SPSR & (1

The text was updated successfully, but these errors were encountered:

Источник

Include Arduino Libraries (SPI.h) with different core causes problems #2573

Comments

NicoHood commented Jan 24, 2015

I’ve installed the current dev version of my HID project. This uses a different Core.

I am not able to include the SPI.h library when the new core is selected. I am able to include it if I move it to the other libraries in the root of the installation instead of in hardware/arduino/avr/libraries. But if I save my sketch and open it again via double click it throws this error again.

There is a difference between starting a sketch via double click or opening a new IDE window and pasting the code. I noticed this several times in other cases.

Using 1.6 rc2, Windows 8.1 Update

The text was updated successfully, but these errors were encountered:

ffissore commented Jul 2, 2015

@NicoHood is this still valid?

NicoHood commented Jul 4, 2015

Yes. If you have 3rd Party AVR core it does not load the default arduino libraries. So I have to copy every library into my core as well and update it with new IDE releases as well.

Just use this sketch to test it:

Edit: tested with nightly of today, now on linux64 bit

matthijskooijman commented Jul 4, 2015

@NicoHood, I guess this means you have a core that consists just of platform.txt, boards.txt and variants, but not a cores directory? e.g. it uses the normal core files verbatim? If so, could you see if you can reproduce this using a minimal platform.txt and boards.txt?

If not, then I guess this is somewhat expected — if you create a custom core, with custom files, there is no guarantee whatsoever that the core-specific libraries from the standard arduino-avr core actually work on your core as well. In fact, I believe that in this case there isn’t even any link to the arduino-avr core that the IDE can use to decide what libraries to use (consider that there might be more third-party avr cores installed that could be a candidate). For this case, the only solution I can imagine is explicitly «inheriting» libraries from a specified core, by using something like «use-libraries-from=arduino:avr» in your platform.txt (exact syntax probably needs tweaking).

NicoHood commented Jul 4, 2015

2nd Option you mentioned. Is there such an option yet or was this just an Idea how to implement it in the future?

matthijskooijman commented Jul 5, 2015

I don’t think the option exists yet, this is just how I would consider implementing it. For now, copying (or symlinking on *NIX) seems the only option (but I’m not 100% sure).

cmaglie commented Jul 6, 2015

Well, actually the feature exists, and the IDE picks the libraries from the referenced cores among the others, I’ve solved that in #1445 (and this is the commit: be30113).

@NicoHood is that happening with your HID core? I’ll take a look to see what’s happening.

NicoHood commented Jul 6, 2015

The attiny variant files uses the Arduino core. What I’ve done is to create a whole new core. And this lacks the libraries, it only looks in the new core for the libraries and thatswhy I have to dupe them. It would be nice to have a setting where you still can choose the default libraries but still use another core.

cmaglie commented Jul 6, 2015

Ahhh, ok now I see. IMHO this is the correct behaviour.

The rationale is that if you fully inherit a core (by providing just a variant/board) then it’s perfectly fine to inherit all the «cores» libraries as well. This is no more true when you provide your own core.

For the same reason the IDE doesn’t allow to «extend» or «partially replace a piece» of a core, for example by providing a single file like USBCore.cpp: in this case you’re on your own and you must copy the whole core.

NicoHood commented Aug 17, 2015

Cant we make those libraries more general as the Keyboard and Mouse library for example which work for both avr and arm? Cant we make avr only, arm only, both libraries that can be globally used?

Since they also appear on the boards manager (i think) they should be useable with different cores, if the core is made for AVR.

I dont need this feature anymore for my project, but I think libraries should be atmic and not connected with the core.

cmaglie commented Aug 17, 2015

The SPI library is strongly tied to a specific CPU, if you look at the source code you’ll see that it makes massive use of registers and atomicity constructs specific for AVRs.
If you try to port the library to another CPU family you’ll end up rewriting 95% of the library (basically, you’ll keep only the class definition, look at the SAM or SAMD implementation to get an idea).

Moreover, every 3rd party core out there (avr, sam/d, stm, teensy, pic32, energia, etc.) have his own implementation of the SPI library, trying to converge them into a unique library it’s like mission impossible and can easily become a maintenance nightmare.

For the record: I’ve (ingenuously?) tried to approach this path in the past but I’ve failed and I had reverted to the current way, that may allow the various implementations/API to diverge but has the advantage to let developers to maintain their own source code independently.

The same rationale applies for other CPU-specific libraries, like Wire for example.

Источник

Читайте также:  Стиральная машина канди ошибка error 3 что это
Оцените статью
toolgir.ru
Adblock
detector