TFTLCD_8BIT_STM32 issue

Post here all questions related to LibMaple core if you can't find a relevant section!
Post Reply
henrosan
Posts: 6
Joined: Fri Jun 25, 2021 6:24 pm

TFTLCD_8BIT_STM32 issue

Post by henrosan »

Hi Guys, I've another problem with the TFTLCD_8bit library I think. Because, the screen went White out of the blue, after 4 days working and adjusting it, and when I got the right AD read. I've modified some pins, but It was working fine without any problem, the main library is here (https://github.com/stevstrong/Adafruit_ ... 8bit_STM32).
What is happening you can question me, only the control pins are working, the data pins don't work anymore.
You can question, if I've tried to see if the pins are working fine without the LCD, and the answer is YES. Only I plug the pins and start the code, they don't send any signal.

----------------------------------------- HEADER ----------------------------------------

Code: Select all

// Data port
#define TFT_DATA_PORT	GPIOA
// Data bits/pins
#define TFT_DATA_SHIFT 0 // take the lower bits/pins 0..7
//#define TFT_DATA_SHIFT 8 // take the higher bits/pins 8..15

//Control pins |RD |WR |RS |CS |RST|
#define TFT_CNTRL_PORT	GPIOB
#define TFT_RD			PB5
#define TFT_WR			PB6
#define TFT_RS			PB7
#define TFT_CS			PB8

#define TFT_RD_MASK		BIT5 // digitalPinToBitMask(TFT_RD) // 
#define TFT_WR_MASK		BIT6 // digitalPinToBitMask(TFT_WR) // 
#define TFT_RS_MASK		BIT7 // digitalPinToBitMask(TFT_RS) // 
#define TFT_CS_MASK		BIT8 // digitalPinToBitMask(TFT_CS) // 

#define TFT_RST			PB9

#define SLOW_WRITE 0   // set to 1 for legacy slow write (using individual digitalWrite()s
[...]

Code: Select all

#if (TFT_DATA_SHIFT==0)
  //#warning "Using lower data nibble..."
	// set the pins to input mode
	#define setReadDir() ( dataRegs->CRL = 0x88888888 )	// set the lower 8 bits as input
	// set the pins to output mode
	#define setWriteDir() ( dataRegs->CRL = 0x33333333 )	// set the lower 8 bits as output

    // set pins to output the 8 bit value
    #if SLOW_WRITE
     inline void write8(uint8_t c) { /*Serial.print(" write8: "); Serial.print(c,HEX); Serial.write(',');*/
    					digitalWrite(PA0, (c&BIT0)?HIGH:LOW);
    					digitalWrite(PA1, (c&BIT1)?HIGH:LOW);
    					digitalWrite(PA2, (c&BIT2)?HIGH:LOW);
    					digitalWrite(PA3, (c&BIT3)?HIGH:LOW);
    					digitalWrite(PA4, (c&BIT4)?HIGH:LOW);
    					digitalWrite(PA5, (c&BIT5)?HIGH:LOW);
    					digitalWrite(PA6, (c&BIT6)?HIGH:LOW);
    					digitalWrite(PA7, (c&BIT7)?HIGH:LOW);
    					WR_STROBE; }
    #else
      #define write8(c) { dataRegs->BSRR = (uint32_t)(0x00FF0000 + ((c)&0xFF)); WR_STROBE; }
      // inline void write8(uint8_t d) { dataRegs->BSRR = (uint32_t)(0x00FF0000 + d); WR_STROBE; };
    #endif
[...]

Code: Select all

class Adafruit_TFTLCD_8bit_STM32 : public Adafruit_GFX {

 public:

  //Adafruit_TFTLCD_8bit_STM32(uint8_t cs, uint8_t cd, uint8_t wr, uint8_t rd, uint8_t rst);
  Adafruit_TFTLCD_8bit_STM32(void);

  void     begin(uint16_t id = 0x9341);
------------------------------------------------------------- my code ----------------------------------------------

Code: Select all

#include <Adafruit_BusIO_Register.h>
#include <Arduino.h>
#include <Adafruit_TFTLCD_8bit_STM32.h>
#include <Adafruit_GFX.h>
#include <gfxfont.h> // Need this library because the fonts are inside it
#include <Fonts/FreeMonoBoldOblique12pt7b.h>
#include <Fonts/FreeSansBold18pt7b.h>
#include <Fonts/Org_01.h>


Adafruit_TFTLCD_8bit_STM32 tft; // tft is an alias to use the functions on TFTLCD library

#define rotation 3 // 

int sensor = 0; // SENSOR READ VARIABLE

// 4046 = 2^12 , THEN THIS CONVERSION HAS 12 BITS
// MAYBE THIS PART OF THE CODE CAN BE CHANGED, BECAUSE THE CONVERSION CAN BE LESS PRECISE
//float conversion = ; // TURNS ANALOG READ INTO VOLTS
//Channels to be acquired.
// I FOUND OUT THAT PINS FOR ADC NEED TO HAVE A DIFFERENTE DECLARATION
// PB0 = 8
// PB1 = 9
uint8_t analogPin[] =  {PB0};   // PB0 is the analog pin
int i = 0; // For the delay

void setup(void) {
  tft.begin(0x9341); // Initialize the Display
  tft.setRotation(rotation);
  //ADC setup start
  pinMode(analogPin[0], INPUT_ANALOG); // PUT THE ANALOG PIN AS ANALOG INPUT, the vector pins starts at 0
  for (int d = 0; d < 6; d++)
  {
    delay(1000); // Give some delay 1 second
  }

  // THIS LOOP WILL GIVE 5 SECONDS OF NON OPERATION IN THIS CODE
  for (int d = 0; d < 2; d++)
  {
    delay(1000); // Give some delay 1 second
  }

}

void loop(void) { // START MAIN FUNCTION
  
  // IN THIS PART OF THE CODE START THE ADC CONVERT
  float result = (float)(analogRead(analogPin[0])/4095.0); // Get the result of AD conversion [0~4095]
  float tensao_value = (float)(analogRead(analogPin[0])/4095.0)*3.30; // Conversion of raw ad reading
  float pressure = (float)(tensao_value/3.30)*20;  // conversion from Vdd value into pressure
  // HERE STARTS THE DISPLAY PART
  tft.setCursor(90, 140); // THE POSITION OF NUMBERS ON THE SCREEN
  tft.fillScreen(BLACK); // BACKGROUND COLOR
  tft.setFont(&Org_01);
  tft.setTextSize(8);
  tft.setTextColor(WHITE);

  // GIVE SOME DELAY (5 SECONDS)
  for (i; i < 3; i++)
  { // INTT OF DELAY
    delay(1000);
  } // END OF DELAY

  i = 0; // Turns i = 0 after de delay
} // END MAIN FUNCTION
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: TFTLCD_8BIT_STM32 issue

Post by stevestrong »

You should go back to a version which worked, before adding analog read.
And then add again new features step by step.
Alternatively, set SLOW_WRITE to 1.
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: TFTLCD_8BIT_STM32 issue

Post by mrburnette »

Always, always, always have a software backup ... hard disk space (or USB flash) is too cheap to not be able to roll-back to a known-good copy.

My procedure is to Zip up my sketch folder monthly...rolling backup on the working HD. Weekly I xcopy my sketches to an external hard drive. Daily, I save-as the sketch with a new date prepended name, example:

20210701_RP2040-Blinky
20210703_RP2040-Blinky Fade
20210704_RP2040-Blinky-Print

When I do the drag-n-drop weekly, I prune everything except the most recent date.

But, no matter how I do things, find a procedure that works for you!
Post Reply

Return to “General discussion”