SPI Registers "was not declared in this scope" on M0 SAMD chip

Hi, I'm trying to get some CC1101 Radio modules talking using the "ELECHOUSE_CC1101.h" library. Using the example code and two Nano boards, it works. When I switch to a either of my SAMD M0 boards (Adalogger Feather M0, Seeeduino XIAO) I get compilation errors (see below).

It appears that the SPCR, SPDR, and SPSR variables are not defined. Also SPE, SPIF, and MSTR are also not defined. I have been reading the spec sheet for the Seeduino XIAO chip and im not sure what to define these as. Do they need to be a hexadecimal number? i.e. 0x0D

C:\Users\JonathanKuhn_j4g3toa\Documents\Arduino\libraries\CC1101_arduino\ELECHOUSE_CC1101.cpp: In member function 'void ELECHOUSE_CC1101::SpiMode(byte)':
C:\Users\JonathanKuhn_j4g3toa\Documents\Arduino\libraries\CC1101_arduino\ELECHOUSE_CC1101.cpp:87:3: error: 'SPCR' was not declared in this scope
SPCR = 0;
^~~~
C:\Users\JonathanKuhn_j4g3toa\Documents\Arduino\libraries\CC1101_arduino\ELECHOUSE_CC1101.cpp:87:3: note: suggested alternative: 'SCL'
SPCR = 0;
^~~~
SCL
C:\Users\JonathanKuhn_j4g3toa\Documents\Arduino\libraries\CC1101_arduino\ELECHOUSE_CC1101.cpp:88:32: error: 'SPE' was not declared in this scope
SPCR = (config & 0x7F) | (1<<SPE) | (1<<MSTR);
^~~
C:\Users\JonathanKuhn_j4g3toa\Documents\Arduino\libraries\CC1101_arduino\ELECHOUSE_CC1101.cpp:88:43: error: 'MSTR' was not declared in this scope
SPCR = (config & 0x7F) | (1<<SPE) | (1<<MSTR);
^~~~
C:\Users\JonathanKuhn_j4g3toa\Documents\Arduino\libraries\CC1101_arduino\ELECHOUSE_CC1101.cpp:88:43: note: suggested alternative: 'PSTR'
SPCR = (config & 0x7F) | (1<<SPE) | (1<<MSTR);
^~~~
PSTR
C:\Users\JonathanKuhn_j4g3toa\Documents\Arduino\libraries\CC1101_arduino\ELECHOUSE_CC1101.cpp:89:9: error: 'SPSR' was not declared in this scope
tmp = SPSR;
^~~~
C:\Users\JonathanKuhn_j4g3toa\Documents\Arduino\libraries\CC1101_arduino\ELECHOUSE_CC1101.cpp:89:9: note: suggested alternative: 'SS'
tmp = SPSR;
^~~~
SS
C:\Users\JonathanKuhn_j4g3toa\Documents\Arduino\libraries\CC1101_arduino\ELECHOUSE_CC1101.cpp:90:9: error: 'SPDR' was not declared in this scope
tmp = SPDR;
^~~~
C:\Users\JonathanKuhn_j4g3toa\Documents\Arduino\libraries\CC1101_arduino\ELECHOUSE_CC1101.cpp:90:9: note: suggested alternative: 'SDA'
tmp = SPDR;
^~~~
SDA
C:\Users\JonathanKuhn_j4g3toa\Documents\Arduino\libraries\CC1101_arduino\ELECHOUSE_CC1101.cpp: In member function 'byte ELECHOUSE_CC1101::SpiTransfer(byte)':
C:\Users\JonathanKuhn_j4g3toa\Documents\Arduino\libraries\CC1101_arduino\ELECHOUSE_CC1101.cpp:101:3: error: 'SPDR' was not declared in this scope
SPDR = value;
^~~~
C:\Users\JonathanKuhn_j4g3toa\Documents\Arduino\libraries\CC1101_arduino\ELECHOUSE_CC1101.cpp:101:3: note: suggested alternative: 'SDA'
SPDR = value;
^~~~
SDA
C:\Users\JonathanKuhn_j4g3toa\Documents\Arduino\libraries\CC1101_arduino\ELECHOUSE_CC1101.cpp:102:12: error: 'SPSR' was not declared in this scope
while (!(SPSR & (1<<SPIF))) ;
^~~~
C:\Users\JonathanKuhn_j4g3toa\Documents\Arduino\libraries\CC1101_arduino\ELECHOUSE_CC1101.cpp:102:12: note: suggested alternative: 'SS'
while (!(SPSR & (1<<SPIF))) ;
^~~~
SS
C:\Users\JonathanKuhn_j4g3toa\Documents\Arduino\libraries\CC1101_arduino\ELECHOUSE_CC1101.cpp:102:23: error: 'SPIF' was not declared in this scope
while (!(SPSR & (1<<SPIF))) ;
^~~~
C:\Users\JonathanKuhn_j4g3toa\Documents\Arduino\libraries\CC1101_arduino\ELECHOUSE_CC1101.cpp:102:23: note: suggested alternative: 'PI'
while (!(SPSR & (1<<SPIF))) ;
^~~~
PI
exit status 1
Error compiling for board Seeeduino XIAO.

The "CC1101_arduino" library seems to be only for the AVR processor family. If you can't find a SAMD-compatible library for that chip you might have to port the library to use the SPI library instead of using the SPI registers directly.

The library is using "low level access" to the SPI peripheral on the AVR, presumably to get improved performance.
Unfortunately, the SAMD21 is a whole different chip family, and the SPI peripheral is MUCH different.

It appears that the SPCR, SPDR, and SPSR variables are not defined. Also SPE, SPIF, and MSTR are also not defined.

It would be essentially useless to redefine those values; you would need to pretty-much re-write the SPI code completely. :frowning:

Thanks for the reply, that is unfortunate. I will look for a alternative library.

John, what would porting the library entail? I have done quite a few Arduino projects but I have yet to modify any libraries in any significant way. Is there a resource that would walk me through this?

Thanks,

There's nothing mysterious about modifying "libraries". It's just code. Copy the source files into the same folder as your .ino sketch. Update the .ino by replacing '#include <...>' with '#include "..."'. That will make the IDE look in that folder first. (I'm not sure if you need to delete the files from the original library installation location.)

Then, update the source code to work with your SAMD board.

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