Zero SPI ICSP Header Wiring and Use in Code

Hey,

I am trying to get a TFT ILI9341 (adafruit) display working on Zero, with no luck.

I have connected the display to the ICSP header as described in schematics:

1 - MISO
3 - Clock
4 - MOSI

I have alose made sure that the display is set to work in SPI mode.

Here is my code with pins definition:

#define TFT_DC 9
#define TFT_CS 10
#define TFT_MOSI 23
#define TFT_CLK 24
#define TFT_MISO 22
#define TFT_RST 11

The code is the example code from Adafruit ILI9341 library called graphics test

Debugging the code, it appears that the line within setup procedure that calls tft.begin() is the culprit and the code does not get past that line. I have made a post on adafruit forum advising of this issue, however I was wondering if my pin definitions were out.

Looking at the pdf schematics and the mux table in variants.cpp I am not able to see where pins 22,23 and 24 are wired on the actual SAMD21 chip.

Can someone please assist in this issue.

Thanks a lot

You did the right thing by connecting the LCD to the SPI port... The problem lies in the Adafruit library. In my experience, Adafruit does a very poor job supporting non-AVR Arduinos. This particular library does contain hardware SPI support but it is written specifically for AVRs and will not work on the Zero. I had to rewrite the entire Adafruit library for the Sharp Memory LCD so it would work on the Zero.

If you want to fix the library yourself let me know as I can share some lessons learned from fixing the Sharp LCD library.

Hi,

If you want help, you should post the whole code and indicate what library you are using.

I'll assume you use the latest Adafruit_ILI9341 library.

You need to call the correct constructor, otherwise, the lib will not use hardware SPI :

Adafruit_ILI9341 tft(int8_t cs, int8_t dc, int8_t rst);

Yes, you are right, this is the library I am using and you are of course correct pointing out that I should have put information about the library and the code. However, I did say that I am using ILI_9341 library and that I am trying to get graphics test example to work. But for the future I shall make sure I post the code.

The constructor that you pointed out is indeed the correct one, however in the example the constructor used only has two parameters for TS and DC values. That is the problem, in their library inside that .cpp file the value for _rst isn't set and is just random. So when it comes to begin() function inside the cpp file pinMode(_rst, OUTPUT) just brakes because pin number simply doesn't exist.

_rst is not random, it is preset to -1 if you don't pass it a value. And if it is equal to -1 it is never used I think. Try to pass it an unused pin number to see if it changes something maybe.

I thought so too, the actual value is after initialisation is (4294967295) a bit far from the desired (-1) :slight_smile:

I shall try passing some unused value and see if it fixes things.

Thank you