ElektorLabs / Arduino

Elektor's Arduino compatible boards, including Elektor Uno R4 with ATmega328PB
21 stars 10 forks source link

error: 'SPDR' was not declared in this scope in Adafruit GFX #8

Closed tr4nt0r closed 5 months ago

tr4nt0r commented 6 years ago

When compiling with a libraries for Adafruit TFTs I get the following errors:

Adafruit_SPITFT_Macros.h: 98:43: error: 'SPDR' was not declared in this scope
   #define HSPI_WRITE(b)            {SPDR = (b); while(!(SPSR & _BV(SPIF)));}
Adafruit_SPITFT.cpp:224: note  in expansion of macro HSPI_WRITE
   HSPI_WRITE(lo)

Adafruit_SPITFT_Macros.h: 98:63: error: 'SPSR' was not declared in this scope
   #define HSPI_WRITE(b)            {SPDR = (b); while(!(SPSR & _BV(SPIF)));}
Adafruit_SPITFT.cpp:224: note  in expansion of macro HSPI_WRITE
   HSPI_WRITE(lo)

I have added this quick and dirty fix to SPI.h and now it compiles without errors:

#define SPDR SPDR0
#define SPSR SPSR0

I think this is a compatibility issue of the Elektor Uno R4s SPI.

elektor-labs commented 6 years ago

The Uno R4 package comes with its own SPI library because there are two SPI modules on the chip: SPI0 & SPI1. On the non-B version of the ATmega328 it is simply called SPI. Programs and libraries that include & use the SPI library will not create problems, but the ones that write or read SPI registers directly do. Your quick & dirty fix is OK.

A similar problem can occur when using the I2C port on the Uno R4.

The Uno R4 SPI (& I2C) library can be found in \packages\Elektor-Uno-R4-for-Arduino-1.8.x\hardware\avr\1.0.0\libraries\