Spark Logic

8-bit|16-bit parallell ILI9341

andreas_ferm Tue Oct 06, 2015 12:16 pm

Good day everyone, I’m all new to stm32 and have previously only done smaller projects on arduiono boards, mostly using already-finished libraries.

Now I reached a point where my programmings skills lack, so instead of optimizing my code i started to look at maple mini and thought it would be excellent to also add a “nice” GUI to my project.

I ended up ordering a chinese 3.2″ tft+touch+sd card combo, but what i didn’t know or think of beforehand was to check the connectivity needed (i just read here and saw all the included libraries for the aforementioned display controller), but all of them are using SPI. So the display came in the mail and i became aware that it didn’t have any SPI interface, (at least not for the display, only for the touch and sd card)

Are there any working options that is available to use with stm32duino? What would be my best chance of getting this to work? (i was initially thinking about going for a MEGA, but choose the maple mini clone as i was impressed with the various tft demos i’ve seen )

I’ve tried looking through “all” of the internet, but have only found small pointers, and none of the really targeted for stm32duino. (i found one post where someone had posted an utft version with support for stm32, which was based on some teensy port, but it was also done for SPI only, and i couldn’t find any ILI9341 tft ‘drivers’ for parallel communication… well there was one for an ILI9481 but i’m not sure if that can be used in direct replacement.

Anyone has a similar display and has it working with a maple mini?

Thanks!
Andreas

Replies

martinayotte Mon Jul 18, 2016 1:02 pm

You need to change “byte” to “gpio_dev*” to get it compiled.

gpio_dev* xp_port = digitalPinToPort(xp);
gpio_dev* yp_port = digitalPinToPort(yp);
gpio_dev* xm_port = digitalPinToPort(xm);
gpio_dev* ym_port = digitalPinToPort(ym);

konczakp Mon Jul 18, 2016 6:06 pm

There is some progress … I can see some readings but they are unstable and unreliable. And it is not showing a pressure …

martinayotte Mon Jul 18, 2016 8:08 pm

I can’t help much other than suggesting to compare your code with the function TouchScreen::pressure(void) from STM32F1/libraries/Touch-Screen-Library_STM/TouchScreen_STM.cpp

ahull Mon Jul 18, 2016 10:05 pm

konczakp wrote:There is some progress … I can see some readings but they are unstable and unreliable. And it is not showing a pressure …

martinayotte Mon Jul 18, 2016 11:16 pm

… also beware that Touch-Screen-Library_STM shows clearly that when use in AVR mode, it is using 10bits ADC, so 1024 range, while in STM32 it is 12bits with 4096 range.

konczakp Tue Jul 19, 2016 11:22 am

This is working sketch in which only range left for calibration

//for STM32
#define YP PB0 // RS must be an analog pin, use "An" notation!
#define XM PA0 // CS must be an analog pin, use "An" notation!
#define YM PB7 // D0 can be a digital pin
#define XP PA1 // D1 can be a digital pin

#define pressureThreshhold 20
#define NUMSAMPLES 6

void setup(void) {
Serial.begin(115200);
}

void loop(void) {

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms (rxplate) across the X plate

getPoint_new(XP, YP, XM, YM, 300);

}

void getPoint_new(byte xp, byte yp, byte xm, byte ym, int rxplate) {

int x, y, z;
int samples[NUMSAMPLES];
byte i, valid;

gpio_dev* xp_port = digitalPinToPort(xp);
gpio_dev* yp_port = digitalPinToPort(yp);
gpio_dev* xm_port = digitalPinToPort(xm);
gpio_dev* ym_port = digitalPinToPort(ym);

byte xp_pin = digitalPinToBitMask(xp);
byte yp_pin = digitalPinToBitMask(yp);
byte xm_pin = digitalPinToBitMask(xm);
byte ym_pin = digitalPinToBitMask(ym);

valid = 1;

pinMode(yp, INPUT);
pinMode(ym, INPUT);

*portOutputRegister(yp_port) &= ~yp_pin;
*portOutputRegister(ym_port) &= ~ym_pin;

pinMode(xp, OUTPUT);
pinMode(xm, OUTPUT);

*portOutputRegister(xp_port) |= xp_pin;
*portOutputRegister(xm_port) &= ~xm_pin;

for (i=0; i<NUMSAMPLES; i++) {
samples[i] = analogRead(yp);
}

insert_sort(samples, NUMSAMPLES);

x = (4096-samples[NUMSAMPLES/2]);

pinMode(xp, INPUT);
pinMode(xm, INPUT);

*portOutputRegister(xp_port) &= ~xp_pin;

pinMode(yp, OUTPUT);
*portOutputRegister(yp_port) |= yp_pin;
pinMode(ym, OUTPUT);

for (i=0; i<NUMSAMPLES; i++) {
samples[i] = analogRead(xm);
}

insert_sort(samples, NUMSAMPLES);

y = (4096-samples[NUMSAMPLES/2]);

// Set X+ to ground
pinMode(xp, OUTPUT);
*portOutputRegister(xp_port) &= ~xp_pin;

// Set Y- to VCC
*portOutputRegister(ym_port) |= ym_pin;

// Hi-Z X- and Y+
*portOutputRegister(yp_port) &= ~yp_pin;
pinMode(yp, INPUT);

int z1 = analogRead(xm);
int z2 = analogRead(yp);

if (rxplate != 0) {

// now read the x
float rtouch;
rtouch = z2;
rtouch /= z1;
rtouch -= 1;
rtouch *= x;
rtouch *= rxplate;
rtouch /= 1024;
z = rtouch;

} else {

z = (1023-(z2+z1));

}

if (! valid) {
z = 0;
}

if (z > pressureThreshhold && z < 1000){
Serial.print("X = "); Serial.print(x);
Serial.print("\tY = "); Serial.print(y);
Serial.print("\tPressure = "); Serial.println(z);
}

}

static void insert_sort(int array[], uint8_t size) {
uint8_t j;
int save;

for (int i = 1; i < size; i++) {
save = array[i];
for (j = i; j >= 1 && save < array[j - 1]; j--)
array[j] = array[j - 1];
array[j] = save;
}
}

martinayotte Tue Jul 19, 2016 4:29 pm

First, you need to be aware that this lib use straight 8 bits of PA7-PA0 for data bus. Moving PA0 to CS you will need to change the write8() function too.
BTW, there was a typo in the comments of Adafruit_ILI9341_8bit_STM.h :
//Pin stm32 |PA7|PA6|PA5|PA4|PA3|PA2|PC1|PA0|

konczakp Tue Jul 19, 2016 4:43 pm

Switching PORTA to PORTB sounds good. How can I do This ?

martinayotte Tue Jul 19, 2016 5:27 pm

Look here :

#define TFT_CNTRL GPIOB
#define TFT_DATA GPIOA

konczakp Tue Jul 19, 2016 7:28 pm

So doing this way I should get :

Port data |D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0 |
Pin stm32 |PB7|PB6|PB5|PB4|PB3|PB2|PB1|PB0|

Control pins |RD |WR |RS |CS |RST|
Pin stm32 |PA4|PA5|PA6|PA7|PA8|

But there is small problem. There is no PB2 pin : http://www.stm32duino.com/download/file.php?id=17

ahull Tue Jul 19, 2016 7:45 pm

PB2 is Boot1, but, I’m not sure if it is usable.

Image

konczakp Tue Jul 19, 2016 7:55 pm

ohhh :/ it is not usable then. So can those pins be shifted to start not from PB0 but from PB3 ? If yes then how to do this in those functions? Will this affect SPI2? I hope not because I will need to use it.

ahull Tue Jul 19, 2016 8:07 pm

konczakp wrote:ohhh :/ it is not usable then. So can those pins be shifted to start not from PB0 but from PB3 ? If yes then how to do this in those functions? Will this affect SPI2? I hope not because I will need to use it.

konczakp Tue Jul 19, 2016 8:16 pm

in this way it will cut me off from both SPI. I need one of the SPI to be usable.

martinayotte Tue Jul 19, 2016 8:17 pm

ahull wrote:PB2 is Boot1, but, I’m not sure if it is usable.

konczakp Tue Jul 19, 2016 8:22 pm

You mean a hardware pull down like 4,7kOhm between PB2 and GND? In this way I’ll be able to use this pin normally and also be able to enter bootloader ?

martinayotte Tue Jul 19, 2016 8:58 pm

Yes ! in my case, I’m using 10K, and within my firmware, the PDB2 is then set as a GPIO output in setup().

konczakp Tue Jul 19, 2016 9:03 pm

okey, so as a conclusion I will set in library code

#define TFT_CNTRL GPIOA
#define TFT_DATA GPIOB

RogerClark Tue Jul 19, 2016 9:27 pm

Boot1 is ignored unless Boot0 is pulled high.

The Maple mini leaves Boot1 floating.

This only becomes an issue if you want to flash via Serial, in which. case you need to make sure Boot1 is pulled low, otherwise flashing via serial is unreliable as the code can get flashed into RAM not ROM

konczakp Wed Jul 20, 2016 11:17 am

Unfortunately after changes screen is not working. I’ve change connections to :

Port data |D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0 |
Pin stm32 |PB7|PB6|PB5|PB4|PB3|PB2|PB1|PB0|

Control pins |RD |WR |RS |CS |RST|
Pin stm32 |PA4|PA5|PA6|PA7|PA8|

Sign in to reply