TFT_22_ILI9225 and Arduino Uno Wifi Rev.2 - Can't compile

Hi,

I am struggling to get the TFT_22_ILI9225 library compile on my Arduino Uno Wifi Rev.2. I’ve searched everywhere for some examples for these two components without luck. I am hoping that someone can support.

I am pasting the beginning of the error (it’s very long and seems to relate to the same issue:

Arduino: 1.8.9 (Linux), Board: "Arduino Uno WiFi Rev2, ATMEGA328"

/home/guillaume/Documents/code/arduino/arduino-ide-resources/libraries/TFT_22_ILI9225/src/TFT_22_ILI9225.cpp: In function 'uint8_t _avr_spi_read()':
/home/guillaume/Documents/code/arduino/arduino-ide-resources/libraries/TFT_22_ILI9225/src/TFT_22_ILI9225.cpp:145:9: error: 'SPDR' was not declared in this scope
         SPDR = r;
         ^~~~
/home/guillaume/Documents/code/arduino/arduino-ide-resources/libraries/TFT_22_ILI9225/src/TFT_22_ILI9225.cpp:145:9: note: suggested alternative: 'SPI'
         SPDR = r;
         ^~~~
         SPI
/home/guillaume/Documents/code/arduino/arduino-ide-resources/libraries/TFT_22_ILI9225/src/TFT_22_ILI9225.cpp:146:17: error: 'SPSR' was not declared in this scope
         while(!(SPSR & _BV(SPIF)));
                 ^~~~
/home/guillaume/Documents/code/arduino/arduino-ide-resources/libraries/TFT_22_ILI9225/src/TFT_22_ILI9225.cpp:146:17: note: suggested alternative: 'SPI'
         while(!(SPSR & _BV(SPIF)));
                 ^~~~
                 SPI

When I open the library file “TFT_22_ILI9225.cpp” for the faulty line I find the code:

    #if defined (__AVR__) || defined(TEENSYDUINO)
    static inline uint8_t _avr_spi_read(void) __attribute__((always_inline));
    static inline uint8_t _avr_spi_read(void) {
        uint8_t r = 0;
        SPDR = r;
        while(!(SPSR & _BV(SPIF)));
        r = SPDR;
        return r;
    }'
        #define HSPI_WRITE(b)        {SPDR = (b); while(!(SPSR & _BV(SPIF)));}
        // #define HSPI_READ()          _avr_spi_read()
    #else
        #define HSPI_WRITE(b)        SPI_OBJECT.transfer((uint8_t)(b))
        // #define HSPI_READ()          HSPI_WRITE(0)
    #endif
    // #define HSPI_WRITE16(s)          HSPI_WRITE((s) >> 8); HSPI_WRITE(s)
    // #define HSPI_WRITE32(l)          HSPI_WRITE((l) >> 24); HSPI_WRITE((l) >> 16); HSPI_WRITE((l) >> 8); HSPI_WRITE(l)
    // #define HSPI_WRITE_PIXELS(c,l)   for(uint32_t i=0; i<(l); i+=2){ HSPI_WRITE(((uint8_t*)(c))[i+1]); HSPI_WRITE(((uint8_t*)(c))[i]); }

Is the “AVR” constant not defined? Where is it defined.

The verbose output of the compiler also indicates that I am using the SPI.h file located at “/home/guillaume/.arduino15/packages/arduino/hardware/megaavr/1.8.2/libraries/SPI/”.

There is another one located here: “/home/guillaume/Applications/arduino-1.8.9/hardware/arduino/avr/libraries/SPI/”

I am not sure which is supposed to be used.

Thanks for the help!

Guillaume

The mega4809 is an AVR8X style chip. It has a lot of Xmega features.

Yes, it is using the correct SPI.h library. The AVR8X SPI registers are called SPI0_CTRLA etc
The traditional AVR has SPCR, etc

No, relying on AVR is not a good way to distinguish an AVR8X chip.

If I get a moment I will port TFT_22_ILI9225 to the m4809.
I have got two NANO-EVERY boards. So I can test on real hardware.

The WiFi Rev2 has been available for a while.
I am surprised that the Arduino Displays Forum has not received whinges yet.
I suspect that the NANO-EVERY will attract more punters.

David.

First off. Update your TFT_22_ILI9225 library via the IDE Library Manager

Then edit line 141 in src/TFT_22_ILI9225.cpp e.g.

    // Standard Byte-by-Byte SPI

    #if defined (__AVR__) || defined(TEENSYDUINO)
    static inline uint8_t _avr_spi_read(void) __attribute__((always_inline));
    static inline uint8_t _avr_spi_read(void) {

to

    // Standard Byte-by-Byte SPI

    #if (defined (__AVR__) || defined(TEENSYDUINO)) && !defined(__AVR_ATmega4809__)
    static inline uint8_t _avr_spi_read(void) __attribute__((always_inline));
    static inline uint8_t _avr_spi_read(void) {

This builds and runs on my NANO-EVERY.

A "better" way to do it is to add a conditional block:

    #if defined(__AVR_ATmega4809__)
    static inline uint8_t _avr_spi_read(void) __attribute__((always_inline));
    static inline uint8_t _avr_spi_read(void) {
        uint8_t r = 0;
        SPI0_DATA = r;
        while(!(SPI0_INTFLAGS & _BV(SPI_IF_bp)));
        r = SPI0_DATA;
        return r;
    }
        #define HSPI_WRITE(b)        {SPI0_DATA = (b); while(!(SPI0_INTFLAGS & _BV(SPI_IF_bp)));}
        // #define HSPI_READ()          _avr_spi_read()
    #elif defined (__AVR__) || defined(TEENSYDUINO)

Please let me know if this is ok for your board.

David.

Hi,

Thanks both for your answers. I've made the changes suggested by David and it's compiling. I'll connect the display and see if things are working.

Thanks a lot!

Guillaume

Since your message Adafruit have updated the Adafruit_GFX library.

Run the IDE Library Manager. Update the libraries. You do not need to do any edits of library files.

David.