STM32 Bluepill MCUFRIEND TFT Data pins Problem

Hi, I'm working on a stm32f103 Bluepill trying to drive a 2.4" TFT Display using MCUFFRIEND Library. In mcufriend_shield.h the control and Data pins of the TFT is clearly specified, but unfortunately the data pins are set as PA0 upto PA7 ( for D0 to D7 ).
here's the problem, i need to use 7 ADC input GPIOs in my project for different analog information conversion and in stm32f103 the ADC channels are restricted to pins on Port A. so i tried to change control and data pins specified for stm32 bluepill in the mcufriend_shield.h file as i'm showing here:
this is the original section for bluepill in mcufriend_shield.h:

#define RD_PORT GPIOB
#define RD_PIN  0  //hardware mod to Adapter.  Allows use of PB5 for SD Card
#define WR_PORT GPIOB
#define WR_PIN  6
#define CD_PORT GPIOB
#define CD_PIN  7
#define CS_PORT GPIOB
#define CS_PIN  8
#define RESET_PORT GPIOB
#define RESET_PIN  9

//configure macros for the data pins
#define write_8(d)    { GPIOA->REGS(BSRR) = 0x00FF << 16; GPIOA->REGS(BSRR) = (d) & 0xFF; }
#define read_8()      (GPIOA->REGS(IDR) & 0xFF)

#define setWriteDir() {GP_OUT(GPIOA, CRL, 0xFFFFFFFF); }
#define setReadDir()  {GP_INP(GPIOA, CRL, 0xFFFFFFFF); }

first i changed the control pins to check if everything is ok and actually there was no problem and everything was fine:

#define RD_PORT GPIOB
#define RD_PIN 0 //hardware mod to Adapter. Allows use of PB5 for SD Card
#define WR_PORT GPIOB
#define WR_PIN 6
#define CD_PORT GPIOB
#define CD_PIN 7
#define CS_PORT GPIOC
#define CS_PIN 13
#define RESET_PORT GPIOC
#define RESET_PIN 14

then to be able to use Port A for ADC operations, i changed the Data pins from B8 upto B15 like this:

#define write_8(d)    { GPIOB->REGS(BSRR) = 0xFF000000 ; GPIOB->REGS(BSRR) = (d<<8) & 0x0000FF00; }
#define read_8()      ((GPIOB->REGS(IDR) & 0xFF00)>>8)
#define setReadDir()  {GP_INP(GPIOB, CRH, 0xFFFFFFFF); }
#define setWriteDir() {GP_OUT(GPIOB, CRH, 0xFFFFFFFF); }

but as i change the data pins, it doesn't anymore.

is there any problem with changing the data pins?
did i make any mistake in the process of data pins change?

i would be really thankful if somebody give me an advice.

BluePill "Shield.h" wiring is

//LCD pins  |D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0 | |RD |WR |RS |CS |RST| |SD_SS|SD_DI|SD_DO|SD_SCK|
//STM32 pin |PA7|PA6|PA5|PA4|PA3|PA2|PA1|PA0| |PB0|PB6|PB7|PB8|PB9| |PA15 |PB5  |PB4  |PB3   | **ALT-SPI1**

You can do Analog on PA0-PA7, PB0-PB1.
If you really need 7 ADC channels you are struggling for GPIO pins. The TFT uses 13 GPIO. 2 of which must be ADC for the Touch. SD card uses 4 GPIO.

If you choose a wiring scheme, I will write the appropriate SPECIAL. But only after you have verified your wiring with LCD_ID_readreg.ino

Note that there are loads of different SPECIALs for BluePill.
Have you looked in C:\Users\ ... \Documents\Arduino\libraries\Mcufriend_kbv\extras\unused\mcufriend_special_2.h

1 Like

Thank you so much David
i never checked mcufriend_special_2.h before and i didn't know there was something like that actually. I just checked now and found another wiring scheme for bluepill there and with a slight change to it, now i've got 6 free ADC channel available that might be enough for my application. the other ADC channel was optional.
thanks for your help, i really appreciate it
that was a life saver.

Life is much easier with a ready-made SPECIAL.

Changing control pins is simple. Changing the Data bus is painful. If you find an existing SPECIAL it saves the work.

Someone wrote an Excel Spreadsheet for BluePill. I can't remember who. And I never really tried it.
I just write the SPECIAL from scratch.

David.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.