[SOLVED] ILI9341 STM32 Blue pill

davemorl
Thu May 31, 2018 8:09 pm
Hi all,

I apologise for this but i am new to stm32 and I’ve been trying to get the display working for 3 days now with no joy. I am obviously missing something simple. I understand there is plenty of previous posts out there on here but after reading all them through im still no further forward.

I am using the graphics test code and i’m recieving the data back through the serial port correctly so the board has programmed correctly.

My code is;

#include "SPI.h"
#include "Adafruit_GFX_AS.h"
#include "Adafruit_ILI9341_STM.h"

// For the Adafruit shield, these are the default.
#define TFT_DC PA15
#define TFT_CS PB4

// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_ILI9341_STM tft = Adafruit_ILI9341_STM(TFT_CS, TFT_DC);
// If using the breakout, change pins as desired
//Adafruit_ILI9341_STM tft = Adafruit_ILI9341_STM(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);

void setup() {
Serial.begin(9600);
Serial.println("ILI9341 Test!");

tft.begin();

// read diagnostics (optional but can help debug problems)
uint8_t x = tft.readcommand8(ILI9341_RDMODE);
Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
x = tft.readcommand8(ILI9341_RDMADCTL);
Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
x = tft.readcommand8(ILI9341_RDPIXFMT);
Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
x = tft.readcommand8(ILI9341_RDIMGFMT);
Serial.print("Image Format: 0x"); Serial.println(x, HEX);
x = tft.readcommand8(ILI9341_RDSELFDIAG);
Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX);

Serial.println(F("Benchmark Time (microseconds)"));

Serial.print(F("Screen fill "));
Serial.println(testFillScreen());
delay(500);


david.prentice
Thu May 31, 2018 8:28 pm
Go on. I would guess you have a Red SPI ILI9341 3.3V display. With or without an XPT2046 touch controller.

These boards must have the RST pin pulled high or under program control.

Add a 10k pullup. Or connect the RST pin to a GPIO pin as nature intended.
Note that Adafruit often omit the RST pin in the examples’ constructors. Their hardware has pullups. They know that the Red boards do not have pullups.

David.


Pito
Thu May 31, 2018 8:40 pm
Try to use a different pins for TFT_CS and _DC, for example

#define TFT_DC PA0
#define TFT_CS PA1


davemorl
Thu May 31, 2018 8:43 pm
Hi David,

Thanks for your reply.

Yep that’s the exact one

I have tried various different libraries, configurations, etc…
I have had this display working on an Uno previously.

I have just connected the reset pin there high with a pull up resistor but still no joy?!


davemorl
Thu May 31, 2018 8:51 pm
Thank God for that!!!

Thanks!

After changing the CS and DC it is working.

Can you give me an explanation why those pins I had been using wouldn’t work?


Pito
Thu May 31, 2018 8:53 pm
Because the PB4, PA15 and few others are used for JTAG under special conditions.
How did you program the BluePill?
With ST_link??

davemorl
Thu May 31, 2018 8:58 pm
With an FTDI usb to serial adapter.

Ok, so will I be able to use these pins still when using the display?


davemorl
Thu May 31, 2018 8:59 pm
My god it is quick compared to the Uno :shock:

I’m now in love!!!!


Pito
Thu May 31, 2018 9:01 pm
You have uploaded your sketch to the BluePill via FTDI Serial?
That means Serial method?

davemorl
Thu May 31, 2018 9:05 pm
With one of these

https://rover.ebay.com/rover/0/0/0?mpre … 2809091934


davemorl
Thu May 31, 2018 9:07 pm
Connected to PA9 and PA10

Pito
Thu May 31, 2018 9:08 pm
I am asking you on the upload method, not interface..
You can upload your sketch via:
1. stm32duino bootloader (USB)
2. Serial (for example the FTDI)
3. Jlink (JTAG)
4. ST_Link (SWD)
5. Black Magic Probe
Which one did you use?

davemorl
Thu May 31, 2018 9:11 pm
Ah sorry my misunderstanding,

Yeah FTDI serial Rx Tx


Pito
Thu May 31, 2018 9:17 pm
Ok, so will I be able to use these pins still when using the display?
Those PB4, PA15.. pins will work as GPIO when the stm32duino’s bootloader is used, afaik.
Otherwise you have to mess with remapping like
afio_cfg_debug_ports(AFIO_DEBUG_NONE);

davemorl
Thu May 31, 2018 9:20 pm
Ok, thanks.

I should be ok for pins on this project. I only have maybe 2 encoders to add so that’s 4 more pins and then maybe the touch screen if I can manage to get that working.

Do you know off the top of your head what pins I can or can’t use for the encoder A and B inputs?


Pito
Thu May 31, 2018 9:28 pm
When using stm32duino bootloader – any.
Use pullups with encoders.
With the special case, afaik, some pins are used as JTAG, and JTAG needs to be disabled therefore (see the function call above).
Try to call the function in your setup() and assign PB4 and PA15 back – you will see.
The affected pins are PB3, PB4, PA15, PA12, PA11 afaik.
I do not know what is the latest status on this – ask our core experts.

Btw, reading the forum, wiki, searching in this forum and g…ling helps too..


davemorl
Thu May 31, 2018 9:38 pm
Will the internal pull ups work ok?

I will have to have a look at using the bootloader. It sounds like it is a lot easier to use.

Thank you for your help. I was about ready to have a tantrum :lol:


Leave a Reply

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