adafruit_ILI9341_STM for SPI2

Please do not post requests
racemaniac
Posts: 695
Joined: Sat Nov 07, 2015 9:09 am

Re: adafruit_ILI9341_STM for SPI2

Post by racemaniac » Mon Apr 18, 2016 5:46 pm

WereCatf wrote:
madias wrote:Ok, while ignoring the comments above, I've recognized, that DMA on SPI2 isn't working as it should. It looks like, its only doing the "normal" transfer. At the first tests, I only saw it was ok, but it's slower than on SPI1.
If I understand the specsheet right, SPI1 and SPI2 run at different speeds, with SPI2 half that of SPI1, so if you're using the same clockdiv it'll obviously result in half the performance. The relevant lines are "APB1:Fmax=24/36MHz" for SPI2 and "APB2:Fmax=48/72MHz" for SPI1 on page 11.
nice catch, just tested in on the spi dma i've just written, and indeed, when switching to spi2, i had to change the divider to obtain the same speed :).
and i've not looked at the code of the frameworks that already exist regarding dma on spi2, but if set up correctly, it works as it should :). I've got it driving a nice neopixel string as a test :).

User avatar
WereCatf
Posts: 166
Joined: Sat Apr 16, 2016 5:30 pm

Re: adafruit_ILI9341_STM for SPI2

Post by WereCatf » Mon Apr 18, 2016 5:58 pm

racemaniac wrote:
WereCatf wrote:
madias wrote:Ok, while ignoring the comments above, I've recognized, that DMA on SPI2 isn't working as it should. It looks like, its only doing the "normal" transfer. At the first tests, I only saw it was ok, but it's slower than on SPI1.
If I understand the specsheet right, SPI1 and SPI2 run at different speeds, with SPI2 half that of SPI1, so if you're using the same clockdiv it'll obviously result in half the performance. The relevant lines are "APB1:Fmax=24/36MHz" for SPI2 and "APB2:Fmax=48/72MHz" for SPI1 on page 11.
nice catch, just tested in on the spi dma i've just written, and indeed, when switching to spi2, i had to change the divider to obtain the same speed :).
and i've not looked at the code of the frameworks that already exist regarding dma on spi2, but if set up correctly, it works as it should :). I've got it driving a nice neopixel string as a test :).
For once I managed to actually be useful, eh? There's this saying about even a blind chicken sometimes finding seed.. :lol:

Anyways, good to know you got it working!

madias
Posts: 813
Joined: Mon Apr 27, 2015 11:26 am
Location: Vienna, Austria

Re: adafruit_ILI9341_STM for SPI2

Post by madias » Tue Apr 19, 2016 6:16 am

Thanks for the tip with the slower SPI2, I'll try to lower the divider.
I have come to another problem on it, but this belongs to nearly every library with SPI:
Assume that you have two SPI devices on one port:
A touch controller (XPT2046 as example)
A ILI9341
The ILI9341 works with a low clock divider (setClockDivider(2))
The XPT2046 needs at least setClockDivider(4) (if not 8)
So in both libraries you need a setClockDivider() line before each SPI execution.
(The example above is a bad example, because I don't use the XPT2046 SPI library, but UTouch -> http://www.rinkydinkelectronics.com/library.php?id=55 this lib runs out of the box and is far more precise than the adafruit one)

User avatar
RogerClark
Posts: 7680
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: adafruit_ILI9341_STM for SPI2

Post by RogerClark » Tue Apr 19, 2016 9:52 am

I have issues with the nRF905 as well on SPI with DIV2, so as I have a board with both nRF905 and ILI9341 I just have to change the SPI divider before and after I make the block of calls to the nRF905 (to slow it down to DIV4)

Adding the call to change the divider in each of the ILI9341 (or the nRF905 lib) code would probably slow things down a bit.

As long as you know a device's limitations, you can probably code more efficiently in your own code (in the sketch), rather than adding code to set the divider in each of the library calls.

madias
Posts: 813
Joined: Mon Apr 27, 2015 11:26 am
Location: Vienna, Austria

Re: adafruit_ILI9341_STM for SPI2

Post by madias » Tue Apr 19, 2016 10:30 am

So I think it's a wise idea to "bundle" SPI devices with the same clock divider on a specific SPI:
Like: NRF and/or XPT2046 on SPI1 and the ILI9341, SD-Card, Winbond EEPROM's on SPI2
For sure it would be better to use "high speed SPI devices" on SPI1, but I won't rewrite the radiohead library (If somebody digged into the code of this lib, know what I mean...)

User avatar
RogerClark
Posts: 7680
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: adafruit_ILI9341_STM for SPI2

Post by RogerClark » Tue Apr 19, 2016 10:38 am

Hi Matthias

I've avoided using RadioHead as it looks like a massive amount of code. it would probably take ages to port, and I'd only end up using 10% of it.

I found a simple nRF905 library and hacked it a lot to get it to work on the STM32 (but as its a hack I'm not adding it as a library, as the code is now rather messy)

But it works fine ;-)

madias
Posts: 813
Joined: Mon Apr 27, 2015 11:26 am
Location: Vienna, Austria

Re: adafruit_ILI9341_STM for SPI2

Post by madias » Tue Apr 19, 2016 12:25 pm

I also use the manicbug NRF24 library, somebody posted here times ago... but it's also a "'#ifdef" hell because of supprt of (too) many platforms. I'm a fan of lightweight separate libraries for each platform, I see no sense in "supporting everything" in one lib.

User avatar
mrburnette
Posts: 2190
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: adafruit_ILI9341_STM for SPI2

Post by mrburnette » Tue Apr 19, 2016 1:03 pm

madias wrote: <...>
I see no sense in "supporting everything" in one lib.
Oh, YES. Such truth... simple, works, supportable.

Now, my personal programming ethic is to build a platform skeleton sketch with the #include "./whatever.h" and correct instantiation and have that in a sketch folder as a template. New projects start by replicating the folder. IMO, 3rd party libs have no need to be off in the Arduino/libraries location.

Ray

stm32user
Posts: 13
Joined: Wed Nov 25, 2015 3:30 pm

Re: adafruit_ILI9341_STM for SPI2

Post by stm32user » Thu Jan 18, 2018 7:04 am

@madias
First of all thank you for the library.

I could not display images on the screen with the following connections.

SPI works on channel 1.
I checked the connections over and over again and the screen remains white.

Code: Select all

#include "SPI.h"
#include <Adafruit_GFX_AS.h>
#include <Adafruit_ILI9341_STM_SPI2.h>  // STM32 DMA Hardware-specific library

#define TFT_CS         PB4
#define TFT_DC         PA15
#define TFT_RST        PB3

Adafruit_ILI9341_STM tft = Adafruit_ILI9341_STM(TFT_CS, TFT_DC, TFT_RST); // Use hardware SPI

SPI Connection
MOSI PB15
MISO PB14
SCK PB13

stevestrong
Posts: 2049
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: adafruit_ILI9341_STM for SPI2

Post by stevestrong » Thu Jan 18, 2018 7:27 am

@stm32user
you can use the default library from the Roger's (or my) repo, it was implemented the possibility to pass the SPI instance as input paramter to the library.
So you can define which SPI interface you would like to use, and also the frequency if different from 36MHz:

Code: Select all

#include <Adafruit_ILI9341_STM.h>  // no need to include SPI.h

SPIClass mySPI(2); // use SPI2
Adafruit_ILI9341_STM tft(TFT_CS, TFT_DC, TFT_RST);

void setup()
{
  ...
  tft.begin(mySPI); // this will set the SPI clock to 36MHz.
  /* alternative:
  uint32_t frequency = 18000000;
  tft.begin(mySPI, frequency);
  */
  ...
}

Post Reply