How to link a library containing patches to SPI.h?

Hello!

Trying to avoid XY Problem, I'll explain what I want to do, and later I'll ask about my attempts to solve the problem.

I want to program AVR32DA processor using Arduino environment. For this purpose, I use DxCore. I want to use SPI, but uC from this series have SPI on pins other than Arduino Nano / Uno. This is not a problem, the creator of DxCore has prepared a revised version of SPI.h that supports these uC. The problem appears at this point - I don't know how to force the Arduino IDE to use the new version of SPI.h instead of the built-in one.

It seems that a simple replacement of the SPI.cpp and SPI.h files in the SPI folder along with the subsequent restart of the environment didn't help. Hence the first question, how to properly attach it?

The second question is of a slightly different nature: in the inbuild version of SPI.h / SPI.cpp I added a simple function that did nothing. I wanted to get a function that would print information whether the inbuild version of the SPI library is included, or the one I tried to add. Of course I included SPI.h in the program. However, the function was not available - an attempt to call it (even if the function body didn't contain anything) returned the information.
'Version' was not declared in this scope
My question - why is this happening?

I change the delimiters <> to "" for the include statement and put the library (generally .cpp and .h files) in the sketch directory. That allows me to modify it for just this one program therefore not compromising other programs that may want to use it. I learned this trick when I got hit with libraries that changed and would no longer compile with an old program.

Please provide more information about this. When you install DxCore, you also install the "platform bundled" SPI library that was specifically provided for use with the DxCore boards:

https://github.com/SpenceKonde/DxCore/tree/master/megaavr/libraries/SPI

Unless you have done something odd, whenever you compile with any of the DxCore boards selected from the Tools > Board menu in the Arduino IDE, that bundled SPI library will automagically be used by the Arduino IDE.

Is it this library that you want to force the IDE to use?:

https://github.com/SpenceKonde/DxCore/tree/master/megaavr/libraries/SPI

Or is there some other revised version that you need it to use?

You probably put it in the wrong place. Because the SPI library is architecture-specific, each Arduino boards platform provides its own version. So you have a different SPI library in use depending on which board you are compiling for. So if you replaced the SPI library that is bundled with the "Arduino AVR Boards" platform of the Uno, then it will not have any effect when compiling for the DxCore boards, and will probably give you a bad day the next time you try to use an Uno.

Probably the same issue. You added the function in a different SPI library from the one that is being used.

If you turn on verbose compilation output, then the Arduino IDE will show you the path of all the libraries that were used after you compile:

  1. Select File > Preferences from the Arduino IDE menus.
  2. Check the box next to "Show verbose output during: ☐ compilation".
  3. Click the OK button.

After compiling any sketch that contains an #include directive for SPI.h, you'll see something like this:

Using library SPI at version 1.0.2 in folder: C:\Users\asdf\AppData\Local\Arduino15\packages\DxCore\hardware\megaavr\1.4.7\libraries\SPI 

SPI is often used as a dependency of other libraries rather than directly by the sketch code. Unless you have done the same bundling of the dependent libraries into your sketch, including updating their #include directives as necessary, they will continue to use the SPI library from the platform.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.