[SOLVED] ILI9431 problem

lapgoch
Sat Feb 24, 2018 2:39 am
Hi.
I am looking for some help.
I have an existing sketch that works ok.
The sketch is used to unlock a door with a rfid card.
It uses a Maple Mini with an ENC28J60 and MFRC522 on the SPI bus.
I would like to add a ILI9431 tft display to show some door entry messages.
When I add the tft display to the same SPI bus and run a basic tft sketch only , the tft display works ok.
When I add the same basic tft sketch to my door lock sketch and run the total sketch I have problems.
The problem is that the ENC28J60 and MFRC522 still work ok , but very slowly.
The ILI9431 tft display only updates one pixel at a time incredibly slowly.
Does anyone know why the ILI9431 is conflicting with the ENC28J60 / MFRC522.
Here is the tft sketch

// tft screen setup
#define CS_TFT PA8
#define DC_TFT PB12
#define RST_TFT PA1
#include <Adafruit_GFX_AS.h>
#include <Adafruit_ILI9341_STM.h>
Adafruit_ILI9341_STM tft = Adafruit_ILI9341_STM(CS_TFT, DC_TFT, RST_TFT);

void setup() {
tft.begin();
tft.setRotation(1);
}

void loop() {
tftDisplay();

}

void tftDisplay() {
tft.setTextSize(1);
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_RED);
tft.drawString("01234",0,0,7);
tft.drawString("56789",0,120,7);
delay(1000);

tft.setTextSize(2);
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_YELLOW);
tft.drawString("1234",0,0,7);
tft.drawString("Lapgoch",50,140,4);
delay(1000);
}


Manny
Sat Feb 24, 2018 11:57 am
Looks to me that the rfid read for loop runs continuously hogging up resources, it should look something like this from the librarys example folder

void loop() {
if ( ! mfrc522.PICC_IsNewCardPresent()) return; // check if rfid card is present
if ( ! mfrc522.PICC_ReadCardSerial()) return; // read rfid card
mfrc522.PICC_HaltA(); // stop reading rfid card

if (rfid.uid.uidByte[0] != nuidPICC[0] ||
rfid.uid.uidByte[1] != nuidPICC[1] ||
rfid.uid.uidByte[2] != nuidPICC[2] ||
rfid.uid.uidByte[3] != nuidPICC[3] ) {
for (int i = 0; i < 4; i++) { // setup loop to read 4 bytes from rfid card
readCard[i] = mfrc522.uid.uidByte[i]; // read card ID byte
stringReadCard[i] = String(readCard[i], HEX); // save card ID byte as hex data
}
// convert rfid hex data to rfid string
String readID = stringReadCard[0] + stringReadCard[1] + stringReadCard[2] + stringReadCard[3];
if (readID != "") checkAccess(readID);
tftDisplay();
}
}


mrburnette
Sat Feb 24, 2018 10:52 pm
I agree with Manny. You really need to use millis() and profile the delta-time for the functions within loop vs the total time to perform 1 full loop. Find out what is hogging your code.

Ray


lapgoch
Sun Feb 25, 2018 7:55 am
Thanks guys.
I am away in Spain at the moment.
So I will try your suggestions when I get back in a couple of weeks time.

lapgoch
Thu Mar 08, 2018 5:29 pm
Hi guys.

I tried your suggestions and sadly it made no difference.
I found that if I remove all the rfid code in the main loop and just leave in the tft code then it still doesn’t work.
If I then comment out the mfrc522.PCD_Init(); in the setup loop then the tft works ok.
Any more ideas ?


mrburnette
Thu Mar 08, 2018 5:57 pm
I’m not a big fan of this logic structure:

void loop() {
if ( ! mfrc522.PICC_IsNewCardPresent()) return; // check if rfid card is present
if ( ! mfrc522.PICC_ReadCardSerial()) return; // read rfid card
mfrc522.PICC_HaltA(); // stop reading rfid card


stevestrong
Thu Mar 08, 2018 8:21 pm
I remember lately there was a problem with ili9341 lib in Roger’s repo in another case, i don’t remember exactly which one.

You could give a try to the ili9341 lib from my repo (www.github.com/stevstrong/Arduino_STM32).


lapgoch
Fri Mar 09, 2018 7:43 am
Hi Ray.
I can’t rework the code as I removed all the card reader code and the tft display still didn’t work.
It was only when I removed the mfrc522.PCD_Init(); from the setup loop that the tft display worked.

Hi Steve.
I will give your library a go later.
Thanks.


lapgoch
Fri Mar 09, 2018 11:18 am
Hi Steve.

When I use your Arduino_STM32 library I get the following compile error message.

arm-none-eabi-g++: error : (build.flags.optimize): No such file or directory

The original Arduino_STM32 library does not have this error.
Any idea what might be wrong ?


stevestrong
Fri Mar 09, 2018 12:24 pm
Did you take only the ILI9341 lib files or the complete core?
Without a complete log of the Arduino IDE message window (verbose on) cannot figure it out.

lapgoch
Fri Mar 09, 2018 12:51 pm
Hi Steve.

I used the whole core.
I will give the ILI9431 library a go.
Thanks.


stevestrong
Fri Mar 09, 2018 12:56 pm
Here is the path: https://github.com/stevstrong/Arduino_S … LI9341_STM

lapgoch
Fri Mar 09, 2018 1:37 pm
Hi Steve.

When I use just the ILI9341_STM and GFX_AS libraries I get a bit further , but fail on a different error.

\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build4c2071f28635de9ec1f5b1d3003eb191.tmp\sketch\demo.ino.cpp.o"
In file included from C:\arduino-1.6.9\portable\sketchbook\maple\demo box\demo\demo.ino:29:0:

C:\arduino-1.6.9\portable\sketchbook\hardware\Arduino_STM32\STM32F1\libraries\Adafruit_ILI9341_STM/Adafruit_ILI9341_STM.h: In member function 'void Adafruit_ILI9341_STM::spiwrite16(uint16_t)':

C:\arduino-1.6.9\portable\sketchbook\hardware\Arduino_STM32\STM32F1\libraries\Adafruit_ILI9341_STM/Adafruit_ILI9341_STM.h:148:48: error: 'class SPIClass' has no member named 'write16'

inline void spiwrite16(uint16_t c) { mSPI.write16(c); } // 8 bit mode

^

Using library SPI at version 1.0 in folder: C:\arduino-1.6.9\portable\sketchbook\hardware\Arduino_STM32\STM32F1\libraries\SPI
Using library UIPEthernet-master at version 2.0.6 in folder: C:\arduino-1.6.9\libraries\UIPEthernet-master
Using library rfid-master at version 1.2.0 in folder: C:\arduino-1.6.9\portable\sketchbook\libraries\rfid-master
Using library Adafruit_GFX_AS in folder: C:\arduino-1.6.9\portable\sketchbook\hardware\Arduino_STM32\STM32F1\libraries\Adafruit_GFX_AS (legacy)
Using library Adafruit_ILI9341_STM in folder: C:\arduino-1.6.9\portable\sketchbook\hardware\Arduino_STM32\STM32F1\libraries\Adafruit_ILI9341_STM (legacy)
exit status 1
Error compiling for board Maple Mini.


stevestrong
Fri Mar 09, 2018 1:48 pm
On the first glance it seems that you are using a non-standard installation.
The Arduino_STM32 file structure should be located under:
C:/Users/<user>/Documents/Arduino/hardware/.
wherein your sketches are normally located under:
C:/Users/<user>/Documents/Arduino/
except the examples of specific libraries.

Beside that, I recommend to use Arduino IDE version 1.8.5 in a separate directory (for example:C:/Users/<user>/Downloads/).

Furthermore, I see that you need my SPI library as well which contains some extra functions compared to Roger’s core.


lapgoch
Fri Mar 09, 2018 2:16 pm
I ended up with the portable version of Arduino because I was having issues compiling any sketch.
My Arduino IDE runs on a XP VM.
I can’t remember the exact compile error message , but it was something to do with the file path being too long.
I am reluctant to upgrade my Arduino IDE at the moment as I might introduce even more issues.
I will just have to keep Googling my problem.
Thanks again for your help.

stevestrong
Fri Mar 09, 2018 2:19 pm
As an alternative, you could eventually use SPI1 for TFT alone, and the rest of devices on SPI2.

lapgoch
Fri Mar 09, 2018 4:42 pm
Yes that is another way.
Sadly I have already made the pcb with everything connected to SPI1.
I have been messing around with the mfrc522 library and find that if I comment out the following lines in the mfrc522.PCD_Init(); then the tft display works.

PCD_WriteRegister(TModeReg, 0x80); // TAuto=1; timer starts automatically at the end of the transmission in all communication modes at all speeds
PCD_WriteRegister(TPrescalerReg, 0xA9); // TPreScaler = TModeReg[3..0]:TPrescalerReg, ie 0x0A9 = 169 => f_timer=40kHz, ie a timer period of 25µs.
PCD_WriteRegister(TReloadRegH, 0x03); // Reload timer with 0x3E8 = 1000, ie 25ms before timeout.
PCD_WriteRegister(TReloadRegL, 0xE8);
PCD_WriteRegister(TxASKReg, 0x40); // Default 0x00. Force a 100 % ASK modulation independent of the ModGsPReg register setting
PCD_WriteRegister(ModeReg, 0x3D); // Default 0x3F. Set the preset value for the CRC coprocessor for the CalcCRC command to 0x6363
PCD_AntennaOn(); // Enable the antenna driver pins TX1 and TX2 (they were disabled by the reset)

Obviously the rfid reader no longer works.
Any thoughts on why writing these values to the rfid card reader would cause issues with the tft display ?


stevestrong
Fri Mar 09, 2018 4:50 pm
It is maybe only the last function call which enables some pins.
Please check your pin mapping, maybe there is some overlapping between them and tft chip select or other pin reserved for tft.

lapgoch
Fri Mar 09, 2018 5:08 pm
Hi Steve.
Could you take a look at my original post , in there is an overview of how it is wired.
Can you spot anything wrong?

stevestrong
Fri Mar 09, 2018 5:15 pm
Ah, ok, I see now your pin mapping.
It looks fine to me.
I really have the feeling that the official ILI9341 lib handles wrongly sometimes the chip select.
For testing, please try to add after each tft function call group a TFT_CS release line:
tft.funct1(); // pseudo code
tft.func2(); // pseudo code
digitalWrite(TFT_CS, HIGH); // real code

lapgoch
Fri Mar 09, 2018 5:31 pm
Tried that and still no joy.
Looks like I am going to have to go back to the drawing board with this one.
Thanks again for all your help.

impulse
Sat Mar 10, 2018 5:10 am
On other platforms I have seen similar issues when SPI transaction support was not enabled.
I haven’t looked into the STM32 core enough to know whether this would be applicable here, but did note that STM32Fx/libraries/SPI/src/SPI.h has transaction support disabled by default.

#define SPI_HAS_TRANSACTION


stevestrong
Sat Mar 10, 2018 8:27 am
Even if this define is not active, I always use SPI.beginTransaction(…) when SPI is involved. It works.
But this has nothing to do with the original issue.

lapgoch
Fri Mar 23, 2018 7:14 pm
Hi.

After much messing about to create a new win7 VM with arduino IDE 1.8.5 with a standard install .
I still had exactly the same issue , the mfrc522 card reader and ili9431 display just would not work together on the same SPI bus.
I finally ditched the libraries <Adafruit_GFX_AS.h> and <Adafruit_ILI9341_STM.h> and just used <Adafruit_GFX.h> and <Adafruit_ILI9341.h>
These worked perfectly , slow but fine for my application.
So there seems to be a conflict with Adafruit STM library and the mfrc522 library.
Being a mere mortal I have no idea how to fix the conflict.
Maybe someone of god like status could shed some light on it.


stevestrong
Fri Mar 23, 2018 10:50 pm
There is a PR on GitHub about the problems with the graphics library functions leaving the SPI bus in 16 bit mode, which is most probably the cause of this problem.
You can try to execute
SPI.beginTransaction(SPISettings(18000000, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT));

lapgoch
Sat Mar 24, 2018 6:43 am
Hi Steve.

Many thanks , you are a star.
Everything is working great now.
I had played around with all different settings for SPI.beginTransastion with no joy.
I did not know about the 8 / 16 bit settings.

Thanks also to Roger Clarke for having similar SPI multi device issues and looking into it.


Leave a Reply

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