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);
}
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();
}
}
Ray
I am away in Spain at the moment.
So I will try your suggestions when I get back in a couple of weeks time.
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 ?
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
You could give a try to the ili9341 lib from my repo (www.github.com/stevstrong/Arduino_STM32).
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.
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 ?
Without a complete log of the Arduino IDE message window (verbose on) cannot figure it out.
I used the whole core.
I will give the ILI9431 library a go.
Thanks.
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.
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.
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.
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 ?
Please check your pin mapping, maybe there is some overlapping between them and tft chip select or other pin reserved for tft.
Could you take a look at my original post , in there is an overview of how it is wired.
Can you spot anything wrong?
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 codeLooks like I am going to have to go back to the drawing board with this one.
Thanks again for all your help.
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
But this has nothing to do with the original issue.
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.
You can try to execute
SPI.beginTransaction(SPISettings(18000000, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT));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.


