Adafruit_ILI9341_8bit_STM icon indicating copy to clipboard operation
Adafruit_ILI9341_8bit_STM copied to clipboard

GPIOA Problem

Open shaddow501 opened this issue 7 years ago • 25 comments

Dear Sir

I have managed to work with the screen thank you for that, but I think something in the library is not performing well.

It seems that the library (even when it set to - #define TFT_DATA_LOW_NIBBLE 1) does affect all GPIOA ports, I use PA14, PA15 to control relays and I see that with no action at all sometimes they change to HIGH mode and cannot be changed to LOW even when I run command digitalWrite(PA14,LOW) they do stay on high mode (I don’t have anything else in my code that address those pins but the relay switch code). Also checked with GPIO PA10, PA11,PA12 and it is the same problem...

I think that something is wrong with this code: _#define write8(c) { uint32_t val = (((c^0x00FF)<<16) | c)<<TFT_DATA_SHIFT; \

                                                                        dataRegs->BSRR = val; WR_STROBE; }_

If I change the pins from PA to PB (pins) or PC (pins) everything works well.

I don’t know what to look in your library that can affect those pins…

This Is a part from the H file.

#define TFT_DATA_PORT GPIOA

// Port data bits D0..D7:

// enable only one from below lines corresponding to your HW setup:

#define TFT_DATA_LOW_NIBBLE 1 // take the lower 8 bits: 0..7

//#define TFT_DATA_HIGH_NIBBLE 1 // take the higher 8 bits: 8..15

//Control pins |RD |WR |RS |CS |RST|

#define TFT_CNTRL_PORT GPIOB

#define TFT_RD PB4

#define TFT_WR PB5

#define TFT_RS PB10

#define TFT_CS PB11

#define TFT_RST PB3 //PB0

#define TFT_RD_MASK BIT4 // digitalPinToBitMask(TFT_RD) //

#define TFT_WR_MASK BIT5 // digitalPinToBitMask(TFT_WR) //

#define TFT_RS_MASK BIT10 // digitalPinToBitMask(TFT_RS) //

#define TFT_CS_MASK BIT11 // digitalPinToBitMask(TFT_CS) //

#if 0

            // use old definition, standard bit toggling, low speed

            #define RD_ACTIVE    digitalWrite(TFT_RD, LOW)

            #define RD_IDLE      digitalWrite(TFT_RD, HIGH)

            #define WR_ACTIVE    digitalWrite(TFT_WR, LOW)

            #define WR_IDLE      digitalWrite(TFT_WR, HIGH)

            #define CD_COMMAND   digitalWrite(TFT_RS, LOW)

            #define CD_DATA      digitalWrite(TFT_RS, HIGH)

            #define CS_ACTIVE    digitalWrite(TFT_CS, LOW)

            #define CS_IDLE      digitalWrite(TFT_CS, HIGH)

            #define CS_ACTIVE_CD_COMMAND      { CS_ACTIVE; CD_COMMAND; }

#else

            // use fast bit toggling, very fast speed!

extern gpio_reg_map * cntrlRegs;

            #define RD_ACTIVE                                                        { cntrlRegs->BRR  = TFT_RD_MASK; }

            #define RD_IDLE                                                                              { cntrlRegs->BSRR = TFT_RD_MASK; }

            #define WR_ACTIVE                                                       { cntrlRegs->BRR  = TFT_WR_MASK; }

            #define WR_IDLE                                                                             { cntrlRegs->BSRR = TFT_WR_MASK; }

            #define CD_COMMAND                                                               { cntrlRegs->BRR  = TFT_RS_MASK; }

            #define CD_DATA                                                                           { cntrlRegs->BSRR = TFT_RS_MASK; }

            #define CS_ACTIVE                                                         { cntrlRegs->BRR  = TFT_CS_MASK; }

            #define CS_IDLE                                                                               { cntrlRegs->BSRR = TFT_CS_MASK; }

            #define CS_ACTIVE_CD_COMMAND      { cntrlRegs->BRR  = (TFT_CS_MASK|TFT_RS_MASK); }

#endif

#define WR_STROBE { WR_ACTIVE; WR_IDLE; }

extern uint8_t read8_(void);

#define read8(x) ( x = read8_() )

extern gpio_reg_map * dataRegs;

#if defined(TFT_DATA_LOW_NIBBLE)

//#warning "Using lower data nibble..."

            // set the pins to input mode

            #define setReadDir() ( dataRegs->CRL = 0x88888888 )     // set the lower 8 bits as input

// #define setReadDir() ( dataRegs->CRL = 0x44444444 ) // set the lower 8 bits as input floating

            // set the pins to output mode

            #define setWriteDir() ( dataRegs->CRL = 0x33333333 )    // set the lower 8 bits as output

            #define TFT_DATA_SHIFT 0

#elif defined(TFT_DATA_HIGH_NIBBLE)

#warning "Using high data nibble..."

            // set the pins to input mode

            #define setReadDir() ( dataRegs->CRH = 0x88888888 )    // set the upper 8 bits as input

            // set the pins to output mode

            #define setWriteDir() ( dataRegs->CRH = 0x33333333 )   // set the lower 8 bits as output

            #define TFT_DATA_SHIFT 8

#endif

// set pins to output the 8 bit value

#if 0 // slow write

#define write8(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) { uint32_t val = (((c^0x00FF)<<16) | c)<<TFT_DATA_SHIFT; \

                                                                            /*Serial.print(" write8: "); Serial.print(val,HEX); Serial.write(',');*/ \

                                                                            dataRegs->BSRR = val; WR_STROBE; }_**

#endif

shaddow501 avatar Aug 22 '17 19:08 shaddow501

I see that you're using stevstrong's repo. Please post this same issue to that repository , because he is the person who wrote this write8 function. It seems weird to me (XOR, (^ operation) is weird and should not work). link to repository of the code that you are using

iwalpola avatar Aug 22 '17 23:08 iwalpola

Dear Isuru

I have found it in the H file. (line 137).

So you say to change from:

#define write8(c) { uint32_t val = (((c^0x00FF)<<16) | c)<<TFT_DATA_SHIFT; \

To:

#define write8(c) { uint32_t val = (c^0x00FF)<<16) | (c&0x00FF))<<TFT_DATA_SHIFT; \

Ok, Ill try and update.

Thanks.

From: Isuru Walpola [mailto:[email protected]] Sent: Wednesday, August 23, 2017 2:51 AM To: iwalpola/Adafruit_ILI9341_8bit_STM [email protected] Cc: shaddow501 [email protected]; Author [email protected] Subject: Re: [iwalpola/Adafruit_ILI9341_8bit_STM] GPIOA Problem (#2)

Hi shadow, where did you find the write8 function that you're using? I cannot see why it should affect PA8-PA15, but the XOR operation will change the value of c. Please re-read BSRR BRR definition: link http://www.stm32duino.com/viewtopic.php?f=18&t=1220&p=15500&hilit=bsrr#p15500 , and definition of XOR (^ operation) link https://www.tutorialspoint.com/cprogramming/c_bitwise_operators.htm Try val=(((c)<<16) | (c))<<TFT_DATA_SHIFT; or val = (((c&0x00FF)<<16) | (c&0x00FF))<<TFT_DATA_SHIFT;

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/iwalpola/Adafruit_ILI9341_8bit_STM/issues/2#issuecomment-324182459 , or mute the thread https://github.com/notifications/unsubscribe-auth/AUIqkwOGFXZcOMO5X7DMqQUnKeB6rPfaks5sa2ligaJpZM4O_FjK . https://github.com/notifications/beacon/AUIqkwstwlvM8NVltnzjI2kxmwkj0GYhks5sa2ligaJpZM4O_FjK.gif

// IMPORTANT: SEE COMMENTS @ LINE 15 REGARDING SHIELD VS BREAKOUT BOARD USAGE.

// Graphics library by ladyada/adafruit with init code from Rossum // MIT license

#ifndef ADAFRUIT_TFTLCD_8BIT_STM32_H #define ADAFRUIT_TFTLCD_8BIT_STM32_H

#define PROGMEM
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
#define pgm_read_word(addr) (*(const unsigned short *)(addr))

#if ARDUINO >= 100 #include "Arduino.h" #else #include "WProgram.h" #endif

#include <Adafruit_GFX.h>

#include <libmaple/gpio.h>

/*****************************************************************************/ // LCD controller chip identifiers #define ID_932X 0 #define ID_7575 1 #define ID_9341 2 #define ID_HX8357D 3 #define ID_UNKNOWN 0xFF

/*****************************************************************************/ #define TFTWIDTH 240 #define TFTHEIGHT 320

// Initialization command tables for different LCD controllers #define TFTLCD_DELAY 0xFF

// For compatibility with sketches written for older versions of library. // Color function name was changed to 'color565' for parity with 2.2" LCD // library. #define Color565 color565

// #define BLACK 0x0000 #define BLUE 0x001F #define RED 0xF800 #define GREEN 0x07E0 #define CYAN 0x07FF #define MAGENTA 0xF81F #define YELLOW 0xFFE0 #define WHITE 0xFFFF // // Define pins and Output Data Registers /*****************************************************************************/

#define TFT_DATA_PORT GPIOA // Port data bits D0..D7: // enable only one from below lines corresponding to your HW setup: #define TFT_DATA_LOW_NIBBLE 1 // take the lower 8 bits: 0..7 //#define TFT_DATA_HIGH_NIBBLE 1 // take the higher 8 bits: 8..15

//Control pins |RD |WR |RS |CS |RST| #define TFT_CNTRL_PORT GPIOB #define TFT_RD PB4 #define TFT_WR PB5 #define TFT_RS PB10 #define TFT_CS PB11 #define TFT_RST PB3 //PB0

#define TFT_RD_MASK BIT4 // digitalPinToBitMask(TFT_RD) // #define TFT_WR_MASK BIT5 // digitalPinToBitMask(TFT_WR) // #define TFT_RS_MASK BIT10 // digitalPinToBitMask(TFT_RS) // #define TFT_CS_MASK BIT11 // digitalPinToBitMask(TFT_CS) //

#if 0 // use old definition, standard bit toggling, low speed #define RD_ACTIVE digitalWrite(TFT_RD, LOW) #define RD_IDLE digitalWrite(TFT_RD, HIGH) #define WR_ACTIVE digitalWrite(TFT_WR, LOW) #define WR_IDLE digitalWrite(TFT_WR, HIGH) #define CD_COMMAND digitalWrite(TFT_RS, LOW) #define CD_DATA digitalWrite(TFT_RS, HIGH) #define CS_ACTIVE digitalWrite(TFT_CS, LOW) #define CS_IDLE digitalWrite(TFT_CS, HIGH) #define CS_ACTIVE_CD_COMMAND { CS_ACTIVE; CD_COMMAND; } #else // use fast bit toggling, very fast speed! extern gpio_reg_map * cntrlRegs; #define RD_ACTIVE { cntrlRegs->BRR = TFT_RD_MASK; } #define RD_IDLE { cntrlRegs->BSRR = TFT_RD_MASK; } #define WR_ACTIVE { cntrlRegs->BRR = TFT_WR_MASK; } #define WR_IDLE { cntrlRegs->BSRR = TFT_WR_MASK; } #define CD_COMMAND { cntrlRegs->BRR = TFT_RS_MASK; } #define CD_DATA { cntrlRegs->BSRR = TFT_RS_MASK; } #define CS_ACTIVE { cntrlRegs->BRR = TFT_CS_MASK; } #define CS_IDLE { cntrlRegs->BSRR = TFT_CS_MASK; } #define CS_ACTIVE_CD_COMMAND { cntrlRegs->BRR = (TFT_CS_MASK|TFT_RS_MASK); } #endif

#define WR_STROBE { WR_ACTIVE; WR_IDLE; }

extern uint8_t read8_(void); #define read8(x) ( x = read8_() )

extern gpio_reg_map * dataRegs;

#if defined(TFT_DATA_LOW_NIBBLE) //#warning "Using lower data nibble..." // set the pins to input mode #define setReadDir() ( dataRegs->CRL = 0x88888888 ) // set the lower 8 bits as input // #define setReadDir() ( dataRegs->CRL = 0x44444444 ) // set the lower 8 bits as input floating // set the pins to output mode #define setWriteDir() ( dataRegs->CRL = 0x33333333 ) // set the lower 8 bits as output #define TFT_DATA_SHIFT 0 #elif defined(TFT_DATA_HIGH_NIBBLE) #warning "Using high data nibble..." // set the pins to input mode #define setReadDir() ( dataRegs->CRH = 0x88888888 ) // set the upper 8 bits as input // set the pins to output mode #define setWriteDir() ( dataRegs->CRH = 0x33333333 ) // set the lower 8 bits as output #define TFT_DATA_SHIFT 8 #endif

// set pins to output the 8 bit value #if 0 // slow write #define write8(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) { uint32_t val = (((c^0x00FF)<<16) | c)<<TFT_DATA_SHIFT;
/Serial.print(" write8: "); Serial.print(val,HEX); Serial.write(',');/
dataRegs->BSRR = val; WR_STROBE; } #endif

/*****************************************************************************/

#define swap(a, b) { int16_t t = a; a = b; b = t; }

/*****************************************************************************/ // **** IF USING THE LCD BREAKOUT BOARD, COMMENT OUT THIS NEXT LINE. **** // **** IF USING THE LCD SHIELD, LEAVE THE LINE ENABLED: ****

//#define USE_ADAFRUIT_SHIELD_PINOUT 1

/*****************************************************************************/ 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 = 0x9328); void drawPixel(int16_t x, int16_t y, uint16_t color); void drawFastHLine(int16_t x0, int16_t y0, int16_t w, uint16_t color); void drawFastVLine(int16_t x0, int16_t y0, int16_t h, uint16_t color); void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t c); void fillScreen(uint16_t color); void reset(void); void setRegisters8(uint8_t *ptr, uint8_t n); void setRegisters16(uint16_t *ptr, uint8_t n); void setRotation(uint8_t x); // These methods are public in order for BMP examples to work: void setAddrWindow(int16_t x1, int16_t y1, int16_t x2, int16_t y2); void invertDisplay(boolean i), pushColors(uint16_t *data, int16_t len, boolean first), drawBitmap(int16_t x, int16_t y, int16_t w, int16_t h, const uint16_t * bitmap);

uint16_t readPixel(int16_t x, int16_t y), readID(void);

private:

void init(), // These items may have previously been defined as macros // in pin_magic.h. If not, function versions are declared: //setLR(void), flood(uint16_t color, uint32_t len); uint8_t driver; };

extern uint16_t color565(uint8_t r, uint8_t g, uint8_t b); extern uint16_t readReg(uint8_t r); extern uint32_t readReg32(uint8_t r); extern void writeCommand(uint16_t c); extern void writeRegister8(uint16_t a, uint8_t d); extern void writeRegister16(uint16_t a, uint16_t d); extern void writeRegister24(uint16_t a, uint32_t d); extern void writeRegister32(uint16_t a, uint32_t d); extern void writeRegisterPair(uint16_t aH, uint16_t aL, uint16_t d);

extern Adafruit_TFTLCD_8bit_STM32 TFT;

#endif

shaddow501 avatar Aug 23 '17 00:08 shaddow501

Sorry you are right,

Didn’t notice…

From: Isuru Walpola [mailto:[email protected]] Sent: Wednesday, August 23, 2017 2:57 AM To: iwalpola/Adafruit_ILI9341_8bit_STM [email protected] Cc: shaddow501 [email protected]; Author [email protected] Subject: Re: [iwalpola/Adafruit_ILI9341_8bit_STM] GPIOA Problem (#2)

and I see now that you're using stevstrong's repo. Please post this same issue to that repository as well.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/iwalpola/Adafruit_ILI9341_8bit_STM/issues/2#issuecomment-324183340 , or mute the thread https://github.com/notifications/unsubscribe-auth/AUIqkwToLG9z0UgYaIRFFbWRPtUt2pEbks5sa2rOgaJpZM4O_FjK . https://github.com/notifications/beacon/AUIqkx4YvDXW8PnFyVkXw1yKE6y0Sn7rks5sa2rOgaJpZM4O_FjK.gif

shaddow501 avatar Aug 23 '17 00:08 shaddow501

I double checked my own thinking, and stevstrong's XOR operation is OK. I'll think about it and see why PA8-PA15 is being affected.

iwalpola avatar Aug 23 '17 00:08 iwalpola

Dear Sir

I have tried the change you have suggested me to do and if the PA14,PA15 before the change were high, after the change they are now low but the same issue cannot change state…

Also tried with your library and set all the control port according to what I use with the other library and I get white screen…

With the other library it is set to:

#define TFT_CNTRL_PORT GPIOB

#define TFT_RD PB4

#define TFT_WR PB5

#define TFT_RS PB10

#define TFT_CS PB11

#define TFT_RST PB3 //PB0

#define TFT_RD_MASK BIT4 // digitalPinToBitMask(TFT_RD) //

#define TFT_WR_MASK BIT5 // digitalPinToBitMask(TFT_WR) //

#define TFT_RS_MASK BIT10 // digitalPinToBitMask(TFT_RS) //

#define TFT_CS_MASK BIT11 // digitalPinToBitMask(TFT_CS) //

With yours it is set to:

#define TFT_CNTRL GPIOB

#define TFT_DATA GPIOA

#define TFT_RD PB4

#define TFT_WR PB5

#define TFT_RS PB10

#define TFT_CS PB11

#define TFT_RST PB3

#define TFT_RD_MASK digitalPinToBitMask(TFT_RD)

#define TFT_WR_MASK digitalPinToBitMask(TFT_WR)

#define TFT_RS_MASK digitalPinToBitMask(TFT_RS)

#define TFT_CS_MASK digitalPinToBitMask(TFT_CS)

#define RD_ACTIVE TFT_CNTRL->regs->BRR = TFT_RD_MASK

#define RD_IDLE TFT_CNTRL->regs->BSRR = TFT_RD_MASK

#define WR_ACTIVE TFT_CNTRL->regs->BRR = TFT_WR_MASK

#define WR_IDLE TFT_CNTRL->regs->BSRR = TFT_WR_MASK

#define CD_COMMAND TFT_CNTRL->regs->BRR = TFT_RS_MASK

#define CD_DATA TFT_CNTRL->regs->BSRR = TFT_RS_MASK

#define CS_ACTIVE TFT_CNTRL->regs->BRR = TFT_CS_MASK

#define CS_IDLE TFT_CNTRL->regs->BSRR = TFT_CS_MASK

What am I missing here…??

From: Isuru Walpola [mailto:[email protected]] Sent: Wednesday, August 23, 2017 3:29 AM To: iwalpola/Adafruit_ILI9341_8bit_STM [email protected] Cc: shaddow501 [email protected]; Author [email protected] Subject: Re: [iwalpola/Adafruit_ILI9341_8bit_STM] GPIOA Problem (#2)

I double checked my own thinking, and stevstrong's XOR operation is OK. I'll think about it and see why PA8-PA15 is being affected.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/iwalpola/Adafruit_ILI9341_8bit_STM/issues/2#issuecomment-324187545 , or mute the thread https://github.com/notifications/unsubscribe-auth/AUIqk4IbcR0m_Y813SMYJT1FwNTxzKqfks5sa3JFgaJpZM4O_FjK . https://github.com/notifications/beacon/AUIqk50IzOmGGrwckrww9f60du0ff1fmks5sa3JFgaJpZM4O_FjK.gif

shaddow501 avatar Aug 23 '17 11:08 shaddow501

Screen is white because there are things in lines 18-30 in the cpp file that need to be changed. (setting control pins as output) I suggest you replace line 18 of my cpp file with pinMode(TFT_RD, OUTPUT); pinMode(TFT_WR, OUTPUT); pinMode(TFT_RS, OUTPUT); pinMode(TFT_CS, OUTPUT);

and line 29 replace with pinMode(TFT_RST, OUTPUT);

Also, you can contact stevstrong on github. He is also on stm32duino.com forums (his username is stevestrong). You can also refer to this documentation of GPIO control (CRH/CRL as alternative for pinMode function, and BRR/BSRR as alternative for digitalWrite function.)

iwalpola avatar Aug 23 '17 11:08 iwalpola

I hope that during testing, you are setting pinMode of your relay pins to OUTPUT before using digitalWrite. Otherwise it will not work.

iwalpola avatar Aug 23 '17 11:08 iwalpola

Sure I do:

This is in the void setup.

pinMode(Relay1, OUTPUT);

pinMode(Relay2, OUTPUT);

pinMode(Relay3, OUTPUT);

pinMode(Relay4, OUTPUT);

digitalWrite(Relay1, LOW);

digitalWrite(Relay2, LOW);

digitalWrite(Relay3, LOW);

digitalWrite(Relay4, LOW);

From: Isuru Walpola [mailto:[email protected]] Sent: Wednesday, August 23, 2017 2:50 PM To: iwalpola/Adafruit_ILI9341_8bit_STM [email protected] Cc: shaddow501 [email protected]; Author [email protected] Subject: Re: [iwalpola/Adafruit_ILI9341_8bit_STM] GPIOA Problem (#2)

I hope that during testing, you are setting pinMode of your relay pins to OUTPUT before using digitalWrite. Otherwise it will not work.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/iwalpola/Adafruit_ILI9341_8bit_STM/issues/2#issuecomment-324304968 , or mute the thread https://github.com/notifications/unsubscribe-auth/AUIqk9yYx1u-pvwiXR469BWiDs0B4-Ioks5sbBHjgaJpZM4O_FjK . https://github.com/notifications/beacon/AUIqkyIzIF7zjSh-QoI8_dS2D53RkQF5ks5sbBHjgaJpZM4O_FjK.gif

shaddow501 avatar Aug 23 '17 11:08 shaddow501

Dear Isuru

I don’t quite understand what to change since the lines are not the same as yours I guess..

From: Isuru Walpola [mailto:[email protected]] Sent: Wednesday, August 23, 2017 2:49 PM To: iwalpola/Adafruit_ILI9341_8bit_STM [email protected] Cc: shaddow501 [email protected]; Author [email protected] Subject: Re: [iwalpola/Adafruit_ILI9341_8bit_STM] GPIOA Problem (#2)

Screen is white because there are things in lines 18-30 in the cpp file that need to be changed. (setting control pins as output) I suggest you replace line 18 of my cpp file with pinMode(TFT_RD, OUTPUT); pinMode(TFT_WR, OUTPUT); pinMode(TFT_RS, OUTPUT); pinMode(TFT_CS, OUTPUT);

and line 29 replace with pinMode(TFT_RST, OUTPUT);

Also, you can contact stevstrong on github. He is also on stm32duino.com forums (his username is stevestrong). You can also refer to this documentation http://www.stm32duino.com/viewtopic.php?f=18&t=1220 of GPIO control (CRH/CRL as alternative for pinMode function, and BRR/BSRR as alternative for digitalWrite function.)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/iwalpola/Adafruit_ILI9341_8bit_STM/issues/2#issuecomment-324304722 , or mute the thread https://github.com/notifications/unsubscribe-auth/AUIqk9zaBUOzLyLTCKT4IbJLsH2vSpwbks5sbBGZgaJpZM4O_FjK . https://github.com/notifications/beacon/AUIqkxJ23T1NBOeocJ8FIt8f5FBdTfCyks5sbBGZgaJpZM4O_FjK.gif

shaddow501 avatar Aug 23 '17 12:08 shaddow501

Also I did open an issue in the stevestrong lib, but I think it is too soon to have an answer…

From: Isuru Walpola [mailto:[email protected]] Sent: Wednesday, August 23, 2017 2:49 PM To: iwalpola/Adafruit_ILI9341_8bit_STM [email protected] Cc: shaddow501 [email protected]; Author [email protected] Subject: Re: [iwalpola/Adafruit_ILI9341_8bit_STM] GPIOA Problem (#2)

Screen is white because there are things in lines 18-30 in the cpp file that need to be changed. (setting control pins as output) I suggest you replace line 18 of my cpp file with pinMode(TFT_RD, OUTPUT); pinMode(TFT_WR, OUTPUT); pinMode(TFT_RS, OUTPUT); pinMode(TFT_CS, OUTPUT);

and line 29 replace with pinMode(TFT_RST, OUTPUT);

Also, you can contact stevstrong on github. He is also on stm32duino.com forums (his username is stevestrong). You can also refer to this documentation http://www.stm32duino.com/viewtopic.php?f=18&t=1220 of GPIO control (CRH/CRL as alternative for pinMode function, and BRR/BSRR as alternative for digitalWrite function.)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/iwalpola/Adafruit_ILI9341_8bit_STM/issues/2#issuecomment-324304722 , or mute the thread https://github.com/notifications/unsubscribe-auth/AUIqk9zaBUOzLyLTCKT4IbJLsH2vSpwbks5sbBGZgaJpZM4O_FjK . https://github.com/notifications/beacon/AUIqkxJ23T1NBOeocJ8FIt8f5FBdTfCyks5sbBGZgaJpZM4O_FjK.gif

shaddow501 avatar Aug 23 '17 12:08 shaddow501

Dear Isuru I dont understand which lines should I change, Do you mean replace the TFT_CNTRL->regs->CRL = (TFT_CNTRL->regs->CRL & 0x0000FFFF) | 0x33330000; and replace with this line? pinMode(TFT_RD, OUTPUT); pinMode(TFT_WR, OUTPUT); pinMode(TFT_RS, OUTPUT); pinMode(TFT_CS, OUTPUT); and replace TFT_CNTRL->regs->CRH = (TFT_CNTRL->regs->CRH & 0xFFFFFFF0) | 0x00000003; with this line? and line 29 replace with pinMode(TFT_RST, OUTPUT); Since line 18 refer to - //Set PB4 - PB7 as output and line 29 refer to - TFT_CNTRL->regs->CRH = (TFT_CNTRL->regs->CRH & 0xFFFFFFF0) | 0x00000003;

//Set PB4 - PB7 as output //Note: CRH and CRL are both 32 bits wide //Each pin is represented by 4 bits 0x3 (hex) sets that pin to O/P TFT_CNTRL->regs->CRL = (TFT_CNTRL->regs->CRL & 0x0000FFFF) | 0x33330000; CS_IDLE; // Set all control bits to HIGH (idle) CD_DATA; // Signals are ACTIVE LOW WR_IDLE; RD_IDLE; if(TFT_RST) { //pinMode(TFT_RST, OUTPUT); //Set PB8 as output TFT_CNTRL->regs->CRH = (TFT_CNTRL->regs->CRH & 0xFFFFFFF0) | 0x00000003; digitalWrite(TFT_RST, HIGH); } //set up 8 bit parallel port to write mode. setWriteDataBus(); }

shaddow501 avatar Aug 25 '17 08:08 shaddow501

Update, I did change the lines accordingly and yes the screen started to work, but it has the same issue all GPIOA is occupied (all 16 bits) I cannot use them. And I do need additional GPIO ports for my code... I have RELAYS connected (based on RTC clock- so additional I2C ports are needed) and I cannot control them since I dont have enough free GPIOS.. Also the PWM fan does not work since it is connected to PA9...

What should I do?

In the stevestrong lib I have option to change the if 0 to if 1 than it does go to the slow write option, with this settings PA8 to PA15 are free and can be controlled but it is very slow and it affect my code that goes really slow...

// set pins to output the 8 bit value #if 1 // slow write (was if 0) #define write8(c) {
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) { uint32_t val = (((c^0x00FF)<<16) | c)<<TFT_DATA_SHIFT;
/Serial.print(" write8: "); Serial.print(val,HEX); Serial.write(',');/
dataRegs->BSRR = val; WR_STROBE; } #endif

When it is changed to 0 it goes to this line - #define write8(c) { uint32_t val = (((c^0x00FF)<<16) | c)<<TFT_DATA_SHIFT;
/Serial.print(" write8: "); Serial.print(val,HEX); Serial.write(',');/
dataRegs->BSRR = val; WR_STROBE; } And than PA8 to PA15 cannot be used...

I think it is similar to your line - #define write8special(c) { TFT_DATA->regs->BSRR = ((~c)<<16) | (c); WR_STROBE; } Since I have the same problem with your lib....

shaddow501 avatar Aug 25 '17 10:08 shaddow501

A problem indeed... It may a problem in the function that sets the data bus to output mode (Using CRL or CRH) also.

There are few options now, especially is you're on a deadline.

  1. Have you tried using PA8-PA15 using CLR, CRH to set pinMode and ODR or BSRR to set state?
  2. You could use an SPI display shield (3 pins)
  3. Use a second microcontroller hooked up to a display, and communicate to that microcontroller over SPI.

iwalpola avatar Aug 26 '17 10:08 iwalpola

Dear Isuru, I am not in a deadline, I like it to work and start using the unit to control 4 relays and PWM fan (based on the RTC temp reading)

Can you show me an example how to use the first option you have suggested ? If I would like to set PA8 to PA15 as an output and control them HIGH and LOW + PWM how should I write it? I would like to use PA8 as a PWM output and PA13 to PA15 as an output for relay. But I have no idea how to write it and if it will actually work...

Update:

I added this line to the "void setup" GPIOA->regs->CRH = (GPIOA->regs->CRH & 0x000FFFF0) | 0x00000008 |0x33300000;

I wanted to set pin PA8 as an input and PA13,PA14,PA15 as an output, other pins unchanged, but I have the same issue I guess the LCD code override this and set all as input...

shaddow501 avatar Aug 26 '17 11:08 shaddow501

Here are some examples https://gist.github.com/iwalpola/6c36c9573fd322a268ce890a118571ca

I read your update, and your code appears to be correct. Its very strange that this is still not working. Did you add the code after the display is initialized (after tft.begin())? If not try moving your line of code to the end of the setup function.

Will you post the problem on STM32duino.com? Maybe someone there has an answer. Also if you share your code on github, others will be able to easily help you. Use git branches to separate different things you have tried.

iwalpola avatar Aug 26 '17 16:08 iwalpola

Yes I did that after tft.begin();

Ilan B. (Mobile)

-----Original Message----- From: Isuru Walpola [email protected] To: iwalpola/Adafruit_ILI9341_8bit_STM [email protected] Cc: shaddow501 [email protected], Author [email protected] Sent: שבת, 26 אוג' 2017 20:00 Subject: Re: [iwalpola/Adafruit_ILI9341_8bit_STM] GPIOA Problem (#2)

Here are some examples https://gist.github.com/iwalpola/6c36c9573fd322a268ce890a118571ca

I read your update, and your code appears to be correct. Its very strange that this is still not working. Did you add the code after the display is initialized (after tft.begin())? If not try moving your line of code to the end of the setup function.

Will you post the problem on STM32duino.com? Maybe someone there has an answer. Also if you share your code on github, others will be able to easily help you. Use git branches to separate different things you have tried.

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/iwalpola/Adafruit_ILI9341_8bit_STM/issues/2#issuecomment-325146888

shaddow501 avatar Aug 26 '17 17:08 shaddow501

Also post there;

https://github.com/rogerclarkmelbourne/Arduino_STM32/issues

From: Isuru Walpola [mailto:[email protected]] Sent: Saturday, August 26, 2017 8:00 PM To: iwalpola/Adafruit_ILI9341_8bit_STM [email protected] Cc: shaddow501 [email protected]; Author [email protected] Subject: Re: [iwalpola/Adafruit_ILI9341_8bit_STM] GPIOA Problem (#2)

Here are some examples https://gist.github.com/iwalpola/6c36c9573fd322a268ce890a118571ca

I read your update, and your code appears to be correct. Its very strange that this is still not working. Did you add the code after the display is initialized (after tft.begin())? If not try moving your line of code to the end of the setup function.

Will you post the problem on STM32duino.com? Maybe someone there has an answer. Also if you share your code on github, others will be able to easily help you. Use git branches to separate different things you have tried.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/iwalpola/Adafruit_ILI9341_8bit_STM/issues/2#issuecomment-325146888 , or mute the thread https://github.com/notifications/unsubscribe-auth/AUIqk_W1iwHdn1ZagT89YuxpXKEBCp-jks5scE8PgaJpZM4O_FjK . https://github.com/notifications/beacon/AUIqkxTCj9vvIIliGbFFJq-sPy2nt2Ltks5scE8PgaJpZM4O_FjK.gif

shaddow501 avatar Aug 26 '17 17:08 shaddow501

I'm so sorry that we can't figure this out... Maybe you could share the code files on github, and I can take a look? In the meantime, why not look into how the digitalWrite() function works, maybe that will give us a clue as to why it leaves PA8-PA15 unaffected. I have a feeling that it has something to do with the size of the value being written to the BSRR register. I read this on a forum: #define GPIO_Pin_0 ((u16)0x0001) /* Pin 0 selected */ #define GPIO_Pin_1 ((u16)0x0002) /* Pin 1 selected */

Notice the (u16) part.

iwalpola avatar Aug 27 '17 14:08 iwalpola

Okay, i tracked down the digitalWrite function. It's in this file ` void digitalWrite(uint8 pin, uint8 val) { if (pin >= BOARD_NR_GPIO_PINS) { return; }

gpio_write_bit(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit, val);

} `

gpio_write_bit is defined in this file

static inline void gpio_write_bit(gpio_dev *dev, uint8 pin, uint8 val) { val = !val; /* "set" bits are lower than "reset" bits */ dev->regs->BSRR = (1U << pin) << (16 * val); }

iwalpola avatar Aug 27 '17 14:08 iwalpola

Dear Isuru

I did sit down with one of our software guys and he thought that the line should be written like this so it will not touch the higher bits.

In your CPP file:

TFT_DATA->regs->BSRR = (((~c)&0x00FF)<<16) | (c&0x00FF);

I haven’t tested it yet but does this make sense?

From: Isuru Walpola [mailto:[email protected]] Sent: Sunday, August 27, 2017 5:23 PM To: iwalpola/Adafruit_ILI9341_8bit_STM [email protected] Cc: shaddow501 [email protected]; Author [email protected] Subject: Re: [iwalpola/Adafruit_ILI9341_8bit_STM] GPIOA Problem (#2)

Okay, i tracked down the digitalWrite function. It's in this https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/master/STM32F1/cores/maple/wirish_digital.cpp file `void digitalWrite(uint8 pin, uint8 val) { if (pin >= BOARD_NR_GPIO_PINS) { return; }

gpio_write_bit(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit, val);

}`

gpio_write_bit is defined in this https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/4021c32fdb809f16a61c073d04e1d8c2c487a767/STM32F1/system/libmaple/include/libmaple/gpio.h file

static inline void gpio_write_bit(gpio_dev dev, uint8 pin, uint8 val) { val = !val; / "set" bits are lower than "reset" bits */ dev->regs->BSRR = (1U << pin) << (16 * val); }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/iwalpola/Adafruit_ILI9341_8bit_STM/issues/2#issuecomment-325201415 , or mute the thread https://github.com/notifications/unsubscribe-auth/AUIqkx-e2vZ0vaNrN914j1x2S5ZCIEXuks5scXvJgaJpZM4O_FjK . https://github.com/notifications/beacon/AUIqk4dDBsASR7Nrfg5VtKRHJNuypAkXks5scXvJgaJpZM4O_FjK.gif

shaddow501 avatar Aug 27 '17 14:08 shaddow501

Yes it makes sense, but if this also does not work, remember that BSRR is a 32 bit word, and 0x00FF is a 16 bit word. Please test and let me know as well!

iwalpola avatar Aug 27 '17 14:08 iwalpola

Ill check it later tonight

Ilan B. (Mobile)

-----Original Message----- From: Isuru Walpola [email protected] To: iwalpola/Adafruit_ILI9341_8bit_STM [email protected] Cc: shaddow501 [email protected], Author [email protected] Sent: יום א׳, 27 אוג' 2017 17:42 Subject: Re: [iwalpola/Adafruit_ILI9341_8bit_STM] GPIOA Problem (#2)

Yes it makes sense, but if this also does not work, remember that BSRR is a 32 bit word, and 0x00FF is a 16 bit word. Please test and let me know as well!

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/iwalpola/Adafruit_ILI9341_8bit_STM/issues/2#issuecomment-325202567

shaddow501 avatar Aug 27 '17 14:08 shaddow501

With the other library (Adafruit_TFTLCD_8bit_STM32.h) we set it like this:

#else

//#define write8(c) { uint32_t val = (((c^0x00FF)<<16) | c)<<TFT_DATA_SHIFT; \ // its original

//#define write8(c) { uint32_t val = ((((c^0x00FF)&0x00FF)<<16) | (c&0x00FF))<<TFT_DATA_SHIFT; \ // Alexandr Spivac edit - for case if need to set/reset only 8 first bits (pins)

#define write8(c) { uint32_t val = ((((c^0x00FF)&0x00FF)<<16) | (c&0x00FF))<<TFT_DATA_SHIFT; \

                                                                            /*Serial.print(" write8: "); Serial.print(val,HEX); Serial.write(',');*/ \

                                                                            dataRegs->BSRR = val; WR_STROBE; }

#endif

If it works Alexandr Spivac would like to have this credit for this lol

From: Isuru Walpola [mailto:[email protected]] Sent: Sunday, August 27, 2017 5:42 PM To: iwalpola/Adafruit_ILI9341_8bit_STM [email protected] Cc: shaddow501 [email protected]; Author [email protected] Subject: Re: [iwalpola/Adafruit_ILI9341_8bit_STM] GPIOA Problem (#2)

Yes it makes sense, but if this also does not work, remember that BSRR is a 32 bit word, and 0x00FF is a 16 bit word. Please test and let me know as well!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/iwalpola/Adafruit_ILI9341_8bit_STM/issues/2#issuecomment-325202567 , or mute the thread https://github.com/notifications/unsubscribe-auth/AUIqk07-as7RTI-KgISfcEKeWAYaOifbks5scYBCgaJpZM4O_FjK . https://github.com/notifications/beacon/AUIqkyhKemWbccyFtm9vsPxJAM1ezH2sks5scYBCgaJpZM4O_FjK.gif

shaddow501 avatar Aug 27 '17 14:08 shaddow501

of course, if it works Alexandr should submit a pull request to both my repo and stevestrong's repo, and we will merge the change (it will appear as an open source contribution on his github profile). cheers!

iwalpola avatar Aug 27 '17 15:08 iwalpola

Dear Isuru

It fixed it :) TFT_DATA->regs->BSRR = (((~c)&0x00FF)<<16) | (c&0x00FF);

From: Isuru Walpola [mailto:[email protected]] Sent: Sunday, August 27, 2017 6:12 PM To: iwalpola/Adafruit_ILI9341_8bit_STM [email protected] Cc: shaddow501 [email protected]; Author [email protected] Subject: Re: [iwalpola/Adafruit_ILI9341_8bit_STM] GPIOA Problem (#2)

of course, if it works Alexandr should submit a pull request to both my repo and stevestrong's repo, and we will merge the change (it will appear as an open source contribution on his github profile). cheers!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/iwalpola/Adafruit_ILI9341_8bit_STM/issues/2#issuecomment-325204297 , or mute the thread https://github.com/notifications/unsubscribe-auth/AUIqk3Z1DzwaforSnVo92jtw7l26VUlFks5scYcvgaJpZM4O_FjK . https://github.com/notifications/beacon/AUIqky6EFMXzyQTDGfivBt77pB3VYI-0ks5scYcvgaJpZM4O_FjK.gif

shaddow501 avatar Aug 27 '17 22:08 shaddow501