ILI9341 multiple SPI

rajdarge
Sun Apr 17, 2016 11:03 am
Trying to Make a datalogger. How unusual !
ANyway Using TFT to display the data. These are the pins I am using
#define SD_CS PA13
#define TFT_CS PA4
#define XPT_CS PA12
#define TFT_DC PB3
#define ONE_WIRE_BUS PA15

Pito
Sun Apr 17, 2016 11:22 am
Double check your SPI clock speeds (sdcard’s vs. tft’s SPI speed), it may happen they differ a lot..

WereCatf
Sun Apr 17, 2016 11:27 am
Without seeing the rest of your code I’d say the problem isn’t with pulling CS-pins down or up and it’s somewhere else. Do you use DMA, for example? Maybe the SPI-bus is still sending stuff out when you pull the CS-pin up. Hard to say from the snippet you posted. Also, while I really, really doubt it’s the problem here, but you should learn the habit of always pulling all the CS-pins up before pulling any of them down — at the moment you’re pulling TFT_CS down while XPT_CS could still also be low. The order in which you pull them up and down can cause trouble if you’re not mindful.

RogerClark
Sun Apr 17, 2016 11:28 am
You could also run the SD on SPI1 and the LCD on SPI2, using setModule(int spi_num) to switch between them.

ie

SPI.setModule(1);

makes SPI = SPI1 (the default)

SPI.setModule(2);

Makes SPI = SPI2

Note, this feature has not been extensively tested, but it definitely works OK in some circumstances.


rajdarge
Sun Apr 17, 2016 12:38 pm
Double check your SPI clock speeds (sdcard’s vs. tft’s SPI speed), it may happen they differ a lot..
Well I’m using the standard SD library which is pretty slow , I believe.
I am using the “ili9341_due_stm” library for the tft with DMA on. There is the sdFat library, but its a bit more difficult to use (at least for a beginner like me).
Maybe the SPI-bus is still sending stuff out when you pull the CS-pin up.
I really don’t know if it is or not, as I am usign other peoples libraries as mentioned above. Do you know of a working example of code that reads the sd card and shows stuff on a TFT? The sdFat demo’s that I have tried only partly work.
this is the module I am using. I believe that its is a common one?

TFT01-2.4SP-03.jpg
TFT01-2.4SP-03.jpg (241.83 KiB) Viewed 2167 times

WereCatf
Sun Apr 17, 2016 1:17 pm
A quick look through the ili9341_due_stm shows that after initializing the library it at no point checks that the SPI-bus settings are correct or anything, like e.g. I use SPI-transactions in my PCD8544 and ILI9341 – stuff all the time — on the ESP8266 the SD-card I use runs at 20MHz and the display runs at 80MHz and it just works beautifully. The ili9341_due_stm looks a bit messy overall, there could be a bug somewhere, too. I wouldn’t know for sure without giving it a more in-depth look, though.

Pito
Sun Apr 17, 2016 2:57 pm
On that tft the sdcard’s signals are wired via R1=R2=R3=1k resistors (?) as they use those resistors to prevent damages when connected to 5V arduinos.
I would replace them with say 22ohm ones (or a wire) when using 3.3V logic only.
It may not help, of course, but the signal’s edges will look better.

madias
Sun Apr 17, 2016 6:52 pm
Here is my port for our adafruit_ILI9341_STM library using SPI2 only (with DMA!) Should works out of the box:

rajdarge
Sun Apr 17, 2016 9:35 pm
WereCatf wrote:A quick look through the ili9341_due_stm shows that after initializing the library it at no point checks that the SPI-bus settings are correct or anything, like e.g. I use SPI-transactions in my PCD8544 and ILI9341 – stuff all the time — on the ESP8266 the SD-card I use runs at 20MHz and the display runs at 80MHz and it just works beautifully. The ili9341_due_stm looks a bit messy overall, there could be a bug somewhere, too. I wouldn’t know for sure without giving it a more in-depth look, though.

WereCatf
Sun Apr 17, 2016 9:58 pm
rajdarge wrote:Is there a way I can get the two libraries (either the ili9341 and the SD.h or sdFat) to work in peace and harmony?

rajdarge
Sun Apr 17, 2016 11:21 pm
WereCatf wrote: The ili9341_due_STM doesn’t use SPI-transactions whereas the ili9341_STM does, so if you can find an SD-library that also supports SPI-transactions you should be good to go. Paul Stoffregen’s xpt2046 touch-sensor library ( https://github.com/PaulStoffregen/XPT20 … screen.git ) also uses SPI-transactions…

greiman’s SdFat ( https://github.com/greiman/SdFat-beta.git ) works great on the ESP8266, supports long filenames and uses SPI-transactions if you enable that setting in the config-file, but I don’t know if it’s yet compatible with the STM32.

Do also note that you shouldn’t have to manually be pulling CS-pins up or down in your sketch — all these libraries do that themselves when needed as long as you’ve told them what CS-pin to use.

WereCatf
Mon Apr 18, 2016 3:18 am
rajdarge wrote:I had most things working on the ESP, but I just ran out of pins, and didn’t want to use a pin multiplexer I had no experience with such things – though I do have some modules.

rajdarge
Mon Apr 18, 2016 4:27 am
you are right, completely off topic, but of great relevance for my project.
I have 5 or so of those modules lying around, so I might very well make use of them.
They may be enough to run the tm1638 modules I am using for keyboard entry.
I can use the software SPI for the TFT, but there is till the problem of the SD and touch screen etc. Can I use the multiplexed pins for CS?
can I use the multiplexed pins for PIR and for neopixels?
Quicker still would be to ask:
What CAN’T I use them for?
IE onewire bus, WS2812, PIR, I2c etc.
I have asked this question at arduino.cc and never really got an answer. I was told that they are slow, but apart from sending stuff to the internet, and interacting with the user, there are no time critical events. Just datalogging for hours, days, months years with battery backup (up to 7 days) temperature breach detection and historical data display.

rajdarge
Mon Apr 18, 2016 4:35 am
WereCatf wrote:The ili9341_due_STM doesn’t use SPI-transactions whereas the ili9341_STM does

WereCatf
Mon Apr 18, 2016 7:17 am
rajdarge wrote:just taking a bit of code from the ILI9341_due.cpp are these SPI transactions?

WereCatf
Mon Apr 18, 2016 7:34 am
rajdarge wrote:Can I use the multiplexed pins for CS?
can I use the multiplexed pins for PIR and for neopixels?
Quicker still would be to ask:
What CAN’T I use them for?
IE onewire bus, WS2812, PIR, I2c etc.

martinayotte
Mon Apr 18, 2016 2:32 pm
Yes, there a bunch of stuff that can be hookup on I2C buses, ADCs, DACs, TempSensors, GPIO expanders of course (personally, I’m using MCP23017), even some UART-I2C bridges, and the famous OLED SSD1306 display.
Using many of those, it is feeing up precious pins to be able to used them in speed sensitive cases.

WereCatf
Tue Apr 19, 2016 1:25 pm
I have an SD-card, an ILI9341 and a PCD8544, all running at different bus-speeds, running on the same SPI-bus:
Image

It all works beautifully, no problems or anything. My version of the PCD8544-lib supports SPI-transactions, SdFat-beta by greiman also does, though the library had a few bugs I had to iron out to get it going, and the original ILI9341-lib by Adafruit does also do SPI-transactions (though I am in the process of cleaning up my so-far private version of it and planning to release it on Github soonish)

To be able to use SPI-transactions, though, you have to dig into the STM32F1’s files and change //#define SPI_HAS_TRANSACTION


rajdarge
Wed Apr 20, 2016 3:28 am
WereCatf wrote:I have an SD-card, an ILI9341 and a PCD8544, all running at different bus-speeds, running on the same SPI-bus:

It all works beautifully, no problems or anything. My version of the PCD8544-lib supports SPI-transactions, SdFat-beta by greiman also does, though the library had a few bugs I had to iron out to get it going, and the original ILI9341-lib by Adafruit does also do SPI-transactions (though I am in the process of cleaning up my so-far private version of it and planning to release it on Github soonish)

To be able to use SPI-transactions, though, you have to dig into the STM32F1’s files and change //#define SPI_HAS_TRANSACTION


WereCatf
Wed Apr 20, 2016 5:37 am
rajdarge wrote:I coudn’t get much to compile with the SdFat library at all…maybe those are the bugs you mention.

WereCatf
Wed Apr 20, 2016 5:40 am
rajdarge wrote:I get what you mean about the I2c Pin expander (not multiplexer) so I don’t think I will be using that at the moment. If only there was a small form factor module that had a multitude of pins and a built in wifi and bluetooth.. Teensy 3.4 anyone? Forget the UNO form factor…. ESP-15F Maybe using a F4 ?

RogerClark
Wed Apr 20, 2016 9:26 am
There was another thread on the AliExpress selling ESP32’s on pre-order (60 day lead time)

Several of us ordered them. (though goodness knows what we will get)


WereCatf
Wed Apr 20, 2016 9:34 am
RogerClark wrote:There was another thread on the AliExpress selling ESP32’s on pre-order (60 day lead time)

Several of us ordered them. (though goodness knows what we will get)


rajdarge
Wed Apr 20, 2016 11:20 am
SOunds very exciting. but. still won’t solve my problem as I will have to rely on other libraries that may yet have more problems :(

toannds
Wed Apr 20, 2016 12:57 pm
rajdarge wrote: Adafruit+GFX_AS: fast, couldn’t get a custom font over, really blocky fonts overall. In the end this one seemed to work the best

mrburnette
Wed Apr 20, 2016 1:41 pm
@ toannds:

Welcome!

Nice display layout. Is it hosted by an STM32? Those ILI9341 displays are so simple to connect via SPI that they run on almost all uC’s … I suspect the really finer fonts kick up the SRAM utilization a bit, though?

Ray


toannds
Wed Apr 20, 2016 4:05 pm
@mrburnette

It connects to an Arduino Mini Pro 5V 16MHz. However, I supply only 3.3V to the Arduino to avoid the 3.3V – 5V level conversion problem. Surprisingly, the Arduino still can run well at 16MHz, with the TFT + DS3231 RTC + HMC5883 sensor, day after day, never crashes :D. I do have another 1.8″ ST7735 connect to STM32 Nucleo-F401RE board though.

Regarding the size for the font: The font takes approx. 7469 bytes. However, as I only need digits and colon to display time and car speed, I removed the rest, after the colon. This reduced the font data size to only around 1552 bytes. The reduction is quite significant because the Atmega328 has only 32Kb flash memory.


mrburnette
Wed Apr 20, 2016 4:15 pm
toannds wrote:<…>
Surprisingly, the Arduino still can run well at 16MHz, with the TFT + DS3231 RTC + HMC5883 sensor, day after day, never crashes :D.
<…>

rajdarge
Wed Apr 20, 2016 8:16 pm
toannds wrote:rajdarge wrote: Adafruit+GFX_AS: fast, couldn’t get a custom font over, really blocky fonts overall. In the end this one seemed to work the best

rajdarge
Thu Apr 21, 2016 3:28 am
Just to report in:
The Adafruit_ILI9341_STM library and the SD library (standard arduino distribution) do work well together. Gone though is the nice font I was using so the readability from across a room is kinda gone. In terms of priorites, I will continue getting the ESP8266 link working and also the breached temperature actions.
Thanks for all the help people.
:D

Leave a Reply

Your email address will not be published. Required fields are marked *